Other Parts Discussed in Thread: UNIFLASH
Hi,
I am using HTTP client example from SDK for GET request. When i use www.google.com as HOSTNAME it works fine and i get google home page html in response to GET request. But when i replace same by my server link, I get response code as 404. However, If I use same server link in PC based software like Postman then I can see my server perfectly gives expected response to GET request. Below is the code snippet. Any guidance on this issue?
--------------------
#define HOSTNAME "my server link"
#define REQUEST_URI "/"
#define USER_AGENT "HTTPClient (ARM; TI-RTOS)"
#define HTTP_MIN_RECV (256)
HTTPClient_extSecParams secparams;
void functionA(void) {
HTTPClient_Handle httpClientHandle;
int16_t statusCode;
httpClientHandle = HTTPClient_create(&statusCode,0);
if(statusCode < 0)
{
Display_printf(display, 0, 0, "httpTask: creation of http client handle failed:%d ",
statusCode);
}
Display_printf(display, 0, 0, "httpTask: client creation ok\n");
ret =
HTTPClient_setHeader(httpClientHandle,
HTTPClient_HFIELD_REQ_USER_AGENT, //HTTPClient_HFIELD_REQ_CONTENT_TYPE,
USER_AGENT,strlen(USER_AGENT)+1,
HTTPClient_HFIELD_PERSISTENT);
if(ret < 0)
{
Display_printf(display, 0, 0, "httpTask: setting request header failed:%d ",
ret);
}
Display_printf(display, 0, 0, "httpTask: set header ok\n");
ret = HTTPClient_connect(httpClientHandle,HOSTNAME,&secparams,0); //&secparams is necessary else this api does not return
if(ret < 0)
{
Display_printf(display, 0, 0, "httpTask: connect failed:%d ",
ret);
}
Display_printf(display, 0, 0, "httpTask: client connect ok\n");
ret =
HTTPClient_sendRequest(httpClientHandle,HTTP_METHOD_GET,REQUEST_URI,
NULL,0, //sizeof(msg),
0);
if(ret < 0)
{
Display_printf(display, 0, 0, "httpTask: send failed:%d ",
ret);
}
Display_printf(display, 0, 0, "httpTask: send request ok\n");
if(ret != HTTP_SC_OK)
{
Display_printf(display, 0, 0, "httpTask: cannot get status:%d ",
ret);
}
Display_printf(display, 0, 0, "HTTP Response Status Code: %d\n ",
ret);
len = 0;
do
{
ret = HTTPClient_readResponseBody(httpClientHandle, data, sizeof(data),
&moreDataFlag);
if(ret < 0)
{
Display_printf(display, 0, 0, "httpTask: response body processing failed:%d ",
ret);
}
Display_printf(display, 0, 0, "%.*s \r\n",ret,data);
len += ret;
}
while(moreDataFlag);
Display_printf(display, 0, 0, "Received %d bytes of payload\n", len);
ret = HTTPClient_disconnect(httpClientHandle);
if(ret < 0)
{
Display_printf(display, 0, 0, "httpTask: disconnect failed:%d ",
ret);
}
HTTPClient_destroy(httpClientHandle);
}
Thanks,
Pradeep