Arduino Forum

Using Arduino => Programming Questions => Topic started by: kotran on Apr 25, 2018, 05:13 am

Title: HttpClient post request return only -1 not 200.
Post by: kotran on Apr 25, 2018, 05:13 am
Hello

I'm sending Image byte data to server.

String payload is like
value=255,216,255,224,0,16,74,70,73,70,0,1,1,1,0,0,0,0,0,0,255,219,0,67,0,12,8,9,11,9,8,12,11,10,11,14,13,12,14,18,30,20,18,17,17,18,37,26,2


         
        HTTPClient httpClient;
         httpClient.begin(targetUrl);
         httpClient.addHeader("Content-Type","application/x-www-form-urlencoded");
         int httpCode = httpClient.POST(payload);
        Serial.println("httpcode");
         Serial.println(httpCode);
        httpClient.end();

but httpCode is always -1
and I checked server's logs. It didn't reach.

below is node js server that image should arrive.

      app.post('/pic',function(request,response){

       }
Title: Re: HttpClient post request return only -1 not 200.
Post by: J-M-L on Apr 25, 2018, 08:22 am
Don't post snippets...

What is in targetUrl? Is that a correct address? Can you reach it from your computer?what happens if you submit your POST?
How is the network configured on your arduino?
What does httpClient.begin(targetUrl); return?
Title: Re: HttpClient post request return only -1 not 200.
Post by: PaulS on Apr 25, 2018, 10:47 am
Quote
I'm sending Image byte data to server.
In the stupidest possible way, apparently.

Why on earth would you send binary data as text?
Title: Re: HttpClient post request return only -1 not 200.
Post by: kotran on Apr 25, 2018, 10:59 am
I thought firstly sending byte data seperated by comma then, on server, I could make string data to image byte .

targetUrl is http://camerauploading.herokuapp.com/pic and work find with postman test(sending sth with post)

Node js server is as below
and for postman post Test. it comes to pic come logs and request method is logged as POST .
but once I request post. I didn't reach here and httpCode result is -1 . not 200

 app.post('/pic',function(request,response){
   console.log("pic come");
  console.log(request.method);
   if (request.method === 'POST') {

   }
  }
Title: Re: HttpClient post request return only -1 not 200.
Post by: PaulS on Apr 25, 2018, 11:23 am
Quote
I thought firstly sending byte data seperated by comma then, on server, I could make string data to image byte .
Are the bytes separated by commas in the image file? NO.

There must be some part of "POST ALL OF YOUR CODE" that you find difficult to understand.
Title: Re: HttpClient post request return only -1 not 200.
Post by: J-M-L on Apr 25, 2018, 10:57 pm
See #1 and provide feedback to all questions