Welcome back and this video, I'm going to show you theoretically how you can send a post request.
OK, so this class is called call API Login Async Task.
So we want to log in.
So I'm going to extend that class a little bit or add a parameter here to the constructor.
So user name will be a string and then the password will also be a string.
OK, so that's the idea behind this.
A login class.
Of course we need to pass something here.
So here I'm just going to say Dennis will be the username and the password will be something like one,
two, three, four, five, six, the greatest password of all.
All right.
So now we can use the username and password which are passed to us from here in order to log in.
So how will we do that?
Well, we sent a request.
So far we have seen how we can get a request or send a request that will give us information.
Now, let's see how we can use a request that will send information.
So we are also in the do in background method.
And we had this.
Do input to output, and instead of using this response code and result and everything in here, I'm
just going to add some more lines of code.
So underneath this connection, do input to the output stuff.
So I'm going to say connection and you can set something like instance follow redirects.
So, for example, if you want to follow any redirect, the Web page starts on what you can make sure
that this will not happen.
So this is just another example of what you can change when it comes to your connection.
So.
This is just another parameter, OK, but now comes the interesting part, so you can set the request
method by doing connection dot request method.
And here you can set multiple different values so you can either use get posed head put, pull options,
trades.
So there are multiple different ones and I'm just going to use to post one.
So be aware that you cannot just send post requests, but you can use other request methods here as
well.
OK, but we're just going to use the post request now.
When doing that, you can set the request properties connection, DOT set request property and here,
for example, the content on the score.
Minus type should be.
Application slash Jason, so their request property will be Jason.
Then the character said that I want to use a connection that said request property, for example, Cha
said, will be UTF minus eight.
And so forth, so you can set different properties here.
All right, so going to add another one, which is going to be accept application, Jason.
So basically, you can see content type application, Jason, there are different types, you can see
XML also exists, CSFI, different types are available here and then the style here or dataset is UTF
eight.
But you can see there are different sets of eyes.
088 59 one, then UTF 16.
So there are multiple different char sets that you could potentially use.
But I'm going to use the UTF eight here and the content type being application JSON.
So these are just a request properties.
And by the way, if a property exists, it will just override its value with a new value.
So if the key, for example, accepts or Shazad or whatever already exists, it will just override it.
All right.
And then the next thing is that we can set whether we want to use cash or not.
So Conexion thought use caches can be set to false, for example.
So some particles do caching of documents.
Occasionally it is important to be able to tunnel through and ignored Acacia's, for example, if the
relo button and the browser is used to use cash flag in a connection is true, then the connections
allow to use whatever caches it can.
And if false catches aren't to be ignored.
So we're just going to ignore caches here.
All right.
And now, instead of reading data, which we did with this puffer reader and the input stream reader,
we're going to write data.
So now we can go ahead and create a verite data output stream, which will be data output stream.
And it needs our connection here.
And to be precise, the connections output stream, so here, output stream.
OK, so we have the connection, we set everything up and now we can write data, and which data do
we want to write?
Well, we want to write Jason objects to it.
So I'm just going to create the adjacent object here, which I'm going to call Jason Request.
And this will be a Jason object, an empty Jason object for now.
And then I can put information to it so I can, for example, put the user name to it.
So that's what I'm going to do.
I'm not going to say the user name should be user name.
And then another Jason request put.
So in this case, it will be put password, password, password.
So these are the ones that we get from our.
Constructor here, so username and password, of course, when we create an amazing task, we need to
pass in the username and password.
All right, so.
That is how we can prepare to Jason request and now we actually need to write that.
So let's write data output stream of right bytes.
So now we're going to write some bytes and which bytes are we going to write?
Well, our Jason request to string.
And now we can flush all right, data output stream and close it, so flush and write data output stream
close.
So this will write the underlying output stream has a sequence of bytes, each character in the string
is written out in sequence by discarding its high light bits, if no exception is thrown to the counter,
written as incremented by the length of us.
So you can see that basically we're just writing whatever.
We have created an adjacent object here to whatever we sent the data to.
All right.
And unfortunately, we cannot test this yet and we will see how to test that later on.
And we will use different tools in the future as well.
But I just wanted to quickly show you how it would be done, theoretically.
All right.
So I'd say let's go over to the next video where we're going to see how we can make all of that a lot
easier.
So this whole JSON object parts and make that significantly easier by using a third party library.
So see you there.