HttpClient Post (-1 (error: connection refused))
Posted: Tue May 30, 2017 1:37 pm
I have posted this question also on Stack overflow but I hope that i will get a faster answer here
I am trying to create a call to a server on the web making use of HttpPost but i keep getting a response of -1 (error: connection refused)
I am able to make an HTTPGet request but my httpPost fails. If i take that same data that i am trying to post and put that into Fiddler and do a post from there i get a 200 OK.
Below is the code that i am trying to execute :
void PostData() {
String data = "mailSend=1&new=1&rec=Gupta+Classic&topic=ddd&reply=ddd&fbSig=bE9";
String url = "https://www.shippingmanager.dk/sh/mailbox.php";
HTTPClient http;
http.setReuse(true);
http.begin(url);
http.addHeader("Host", "www.shippingmanager.dk");
http.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0");
http.addHeader("Accept-Language", " en-US,en;q=0.5");
http.addHeader("Accept-Encoding", " gzip, deflate, br");
http.addHeader("Content-Type", " application/x-www-form-urlencoded; charset=UTF-8");
http.addHeader("X-Requested-With", " XMLHttpRequest");
http.addHeader("Referer", " https://www.shippingmanager.dk/sh/?fb_s ... manager.dk");
http.addHeader("Connection", "keep-alive");
http.addHeader("Pragma", " no-cache");
http.addHeader("Cache-Control", " no-cache");
int result = http.POST(data);
http.writeToStream(&Serial);
http.end();
}
this is the raw text that i post in Fiddler to do the post :
POST https://www.shippingmanager.dk/sh/mailbox.php HTTP/1.1
Host: www.shippingmanager.dk
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: https://www.shippingmanager.dk/sh/?fb_s ... manager.dk
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
mailSend=1&new=1&rec=Gupta+Classic&topic=ddd&reply=ddd&fbSig=J9
Please can someone point me to my problem.
I also tried the code in this link and that also failed me
viewtopic.php?f=29&t=14054
I am trying to create a call to a server on the web making use of HttpPost but i keep getting a response of -1 (error: connection refused)
I am able to make an HTTPGet request but my httpPost fails. If i take that same data that i am trying to post and put that into Fiddler and do a post from there i get a 200 OK.
Below is the code that i am trying to execute :
void PostData() {
String data = "mailSend=1&new=1&rec=Gupta+Classic&topic=ddd&reply=ddd&fbSig=bE9";
String url = "https://www.shippingmanager.dk/sh/mailbox.php";
HTTPClient http;
http.setReuse(true);
http.begin(url);
http.addHeader("Host", "www.shippingmanager.dk");
http.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0");
http.addHeader("Accept-Language", " en-US,en;q=0.5");
http.addHeader("Accept-Encoding", " gzip, deflate, br");
http.addHeader("Content-Type", " application/x-www-form-urlencoded; charset=UTF-8");
http.addHeader("X-Requested-With", " XMLHttpRequest");
http.addHeader("Referer", " https://www.shippingmanager.dk/sh/?fb_s ... manager.dk");
http.addHeader("Connection", "keep-alive");
http.addHeader("Pragma", " no-cache");
http.addHeader("Cache-Control", " no-cache");
int result = http.POST(data);
http.writeToStream(&Serial);
http.end();
}
this is the raw text that i post in Fiddler to do the post :
POST https://www.shippingmanager.dk/sh/mailbox.php HTTP/1.1
Host: www.shippingmanager.dk
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: https://www.shippingmanager.dk/sh/?fb_s ... manager.dk
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
mailSend=1&new=1&rec=Gupta+Classic&topic=ddd&reply=ddd&fbSig=J9
Please can someone point me to my problem.
I also tried the code in this link and that also failed me
viewtopic.php?f=29&t=14054