[Question] HTTP POST

XverhelstX

Well-Known Member
Licensed User
Longtime User
Hey everyone,

I have finally succeeded in live-streaming to my webpage.
Although, I work with HTTP POST Method and everytime the Timer runs of, it executes some Java Code that initializes a new HTTP Client and sends the data. This takes long and gives me sometimes an ANR message.

B4X:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new
HttpPost(WebServer);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();

1) Is there a way in B4A to keep a connection open between the device and the webserver or doesn't this really matter?

2) I use this:

B4X:
ArrayList<NameValuePair> nameValuePairs = new
ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("image",ba1));
nameValuePairs.add(new BasicNameValuePair("PHPProtect",FrameProtect));

in my Java to pass the data to my PHP code.
B4X:
if (isset($_REQUEST['PHPProtect'])) {
         $isProtected=$_REQUEST['PHPProtect'];

How should I assign the correct data ba1 to image and FrameProtect to PHPProtect within the POST Method to send to the webserver.

3) How can you change the time out settings until a ANR message appears.

Thanks,

XverhelstX
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
Because I have problems with this:

B4X:
ArrayList<NameValuePair> nameValuePairs = new
        ArrayList<NameValuePair>();
           nameValuePairs.add(new BasicNameValuePair("image",ba1));
           nameValuePairs.add(new BasicNameValuePair("PHPProtect",FrameProtect));

Don't know how to add those POST Methods to send them in B4A.
With Stringbuilder, but how would they know that ba1 is a member of "image" and FrameProtect from PHPProtect.

XverhelstX
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The Http library is a complicated library that allows you to make calls in the background and thus avoid "ANR" dialogs. I recommend you to use it instead.

If you are using HttpUtils then you can use HttpUtils.PostString("key1=value1&key2=value2&key3=value3")

You should of course replace key and value with your parameters.
 
Upvote 0
Top