Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 12 months ago.
Wolf SSL HTTP POST
Hello everyone, i´m trying to make a http post request with wolf ssl to my apache2. The http get request is working properly and i get a decent response from my server, but somehow the put request isnt. This is the php script i´m using for checking if post request was succesfull:http://pastebin.com/6KMA10h7
php script
<?php
if(isset($_POST['name'])){
echo "succes";
file_put_contents('./echofile.txt','succes');
}
else
{
echo "fail";
file_put_contents('./echofile.txt','fail');
}
?>
And this is my main.cpp: http://pastebin.com/tPnCy2Nu
main.cpp
#include "mbed.h"
#include "EthernetInterface.h"
#include "HTTPClient.h"
#include "getline.h"
#include "IHTTPData.h"
EthernetInterface eth;
HTTPClient http;
size_t data_out_len;
char recvBuff[1024*20];
char http_post[10]="name=pete";
void net_main(void const *av)
{
int ret ;
char post_get[20];
char url[100];
HTTPText http_data_out(http_post);
HTTPText http_data_in(recvBuff);
printf("\n\rpost=%s\n\r",http_post);
eth.init(); //Use DHCP
printf("HTTP Client, Starting,...\n\r") ;
while(1) {
if(eth.connect() == 0)break ;
printf("Retry\n\r") ;
}
// http.dumpReqHeader(false);
// http.dumpResHeader(false);
while(1) {
getline("URL: ", url, sizeof(url)) ;
if(strlen(url) == 0)return ;
/*** HTTP ***/
getline("\n\rPOST OR GET: ",post_get,sizeof(post_get));
if(!strcmp(post_get,"post"))
{
ret=http.post(url,http_data_out,&http_data_in);
printf("\r\nret=%d\r\nResult1=%s\n\r",ret,recvBuff);
}
else if (!strcmp(post_get,"get"))
{
ret = http.get(url, recvBuff, sizeof(recvBuff));
}
else
printf("wrong input\r\n");
if (!ret) {
printf("Result: %s\n\r", recvBuff);
} else {
printf("Error - ret = %d - HTTP return code = %d\n\r", ret, http.getHTTPResponseCode());
}
}
}
int main(void)
{
#define STACK_SIZE 24000
Thread t(net_main, NULL, osPriorityNormal, STACK_SIZE);
while (true) {
Thread::wait(1000);
}
}
The main.cpp is basically the wolfssl example with some minor changes to try out http post.
So everytime i try a post request it fails and writes that fail into the echofile.txt. I think i have configured the apache properly as the get request is succesfull.
I would be glad for any ideas / help.
Greetings