Quantcast
Viewing all articles
Browse latest Browse all 4845

Created Unassigned: Proxy Use Cuts Response Body [87]

We were implementing the use of a proxy in making simple get requests (code below), and we noticed that when we receive the response from this call, the body is an empty string. This does not necessarily happen on every web request we have made using this code, but the example provided (http://whatismyip.com) seems to cause this issue. When we take the proxy code out, we are able to receive a response body.

We have implemented a solution that works for us using the standard WinHttp but were concerned that this may be a bug in Casablanca that would need to be addressed.

```
//Build the proxy
http_client_config client_config;
web_proxy wp(L"http://<*PROXY_IP*>:<*PROXY_PORT*>");
client_config.set_proxy(wp);

//Build the request
http_request request;
request.set_method(methods::GET);
request.headers().add(L"Accept", L"text/html, application/xhtml+xml, */*");
request.headers().add(L"Accept-Language", L"en-US");
request.headers().add(L"User-Agent", L"Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko");
request.headers().add(L"DNT", L"1");
request.headers().add(L"Connection", L"Keep-Alive");
request.headers().add(L"Cookie", L"<*COOKIES*>");

//Setup the client with the proxy
http_client client(L"http://www.whatismyip.com/", client_config);

//Get the response
pplx::task<http_response> resp = client.request(request);

//Wait for the response
while (!resp.is_done())
std::this_thread::sleep_for(std::chrono::milliseconds(1000));

//Get the response
http_response resp2 = resp.get();

//Extract the headers
http_headers Headers = resp2.headers(); //Headers received correctly

//Extract the body
wstring Body = resp2.extract_string().get().c_str(); //Body is empty (L"")
```

Viewing all articles
Browse latest Browse all 4845

Trending Articles