login about faq

For this particular URL ("http://www.sinyi.com.tw/"), the call to quickGetStr fails because the server returns a "406 Not Acceptable" response code.

    const char url = "http://www.sinyi.com.tw/";
    const char html = http.quickGetStr(url);
    if (!html)
    {
    printf("qa_httpGet failed.n");
    printf("%sn",http.lastErrorText());
    }

asked Jul 22 '14 at 11:05

chilkat's gravatar image

chilkat ♦♦
11.8k316358420


For some reason, this web server responds with a 406 Not Acceptable to the 1st GET request, but included in the response header is a Set-Cookie response header. The solution is to have your app automatically save/send cookies. Issue the 1st GET to get the 406 response, then re-issue the GET a 2nd time, which automatically sends the cookie with the GET request, and this results in a 200 OK.

    const char *url = "http://www.sinyi.com.tw/";

http.put_SendCookies(true);
http.put_SaveCookies(true);
http.put_CookieDir("memory");

const char *html = http.quickGetStr(url);
if (!html)
{
printf("qa_httpGet failed.\n");
printf("%s\n",http.lastErrorText());
}
// Send the request again, but this time the cached cookie(s) from the 1st response 
// will be included.
html = http.quickGetStr(url);
if (!html)
{
printf("qa_httpGet failed.\n");
printf("%s\n",http.lastErrorText());
return false;
}
printf("%s\n",http.lastErrorText());
printf("qa_httpGet success.\n");
link

answered Jul 22 '14 at 11:09

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×186
×5
×1
×1

Asked: Jul 22 '14 at 11:05

Seen: 1,052 times

Last updated: Jul 22 '14 at 11:09

powered by OSQA