How to download XML response file

Feb 27, 2014 at 2:48 AM
Hello,

I'm working with some Web Mapping servers (WMS servers), and I'm able to download the XML response of some of them using the code from https://casablanca.codeplex.com/discussions/447267.

But, some of the servers "popup" the xml response, instead of put it in the browser, and I'm unable to save that response to a file. How can I save that data?. Any help will be appreciated.

Example of WMS server that "popup" the response (copy link in browser):

http://mapconnect.ga.gov.au/wmsconnector/com.esri.wms.Esrimap?Servicename=GDA94_MapConnect_SDE_250kmap_WMS&SERVICE=WMS&REQUEST=GetCapabilities

Example of WMS server that works (copy link in browser):

http://demo.lizardtech.com/lizardtech/iserv/ows?SERVICE=WMS&REQUEST=GetCapabilities

Thanks in advance.

Miguel
Coordinator
Feb 27, 2014 at 7:25 PM
Edited Feb 27, 2014 at 7:26 PM
Hi azcar,

By using fiddler, I found even the server "popup", the xml is still part of the response body. The follow test code works for both of the WMS server links.
#include "cpprest/filestream.h"
#include "cpprest/http_client.h"

using namespace utility;
using namespace web;
using namespace web::http;
using namespace web::http::client;
using namespace concurrency::streams;
using namespace web::http::client;

int _tmain(int argc, _TCHAR* argv [])
{
    auto fileName = L"D:\\sample.xml";

    // Pop up
    web::http::uri_builder uribuilder(L"http://mapconnect.ga.gov.au/wmsconnector/com.esri.wms.Esrimap?");
    uribuilder.append_query(L"Servicename", L"GDA94_MapConnect_SDE_250kmap_WMS");
    uribuilder.append_query(L"SERVICE", L"WMS");
    uribuilder.append_query(L"REQUEST", L"GetCapabilities");

    ////http://demo.lizardtech.com/lizardtech/iserv/ows?SERVICE=WMS&REQUEST=GetCapabilities 
    //web::http::uri_builder uribuilder(L"http://demo.lizardtech.com/lizardtech/iserv/ows?");
    //uribuilder.append_query(L"SERVICE", L"WMS");
    //uribuilder.append_query(L"REQUEST", L"GetCapabilities");

    http_client client(uribuilder.to_uri());

    client.request(methods::GET).then([=](http_response response){
        return response.body();
    }).then([=](concurrency::streams::istream is){
        concurrency::streams::streambuf<uint8_t> rwbuf = concurrency::streams::file_buffer<uint8_t>::open(fileName).get();
        is.read_to_end(rwbuf).get();
        rwbuf.close();
    }).wait();

    return 0;
}
The code is not so clean, I hope it can help you.
Feb 27, 2014 at 10:52 PM
Edited Feb 27, 2014 at 10:58 PM
Hi zhelu, thanks for your quick reply.

Unfortunately, the code provided for you doesn't work in the popup server, but works in the normal server with my configuration: VS 2013 Professional, and using Casablanca in my project via NuGet. Below is the code that I'm using, similar to you, but more simplified (Please note that I'm using a different "pop up" server, because the original one is offline):
int _tmain(int argc, _TCHAR* argv[])
{
    auto fileName = L"D:\\sample.xml";

    // Pop up, DOES NOT work
    web::http::uri_builder uribuilder(L"http://www.ga.gov.au/flood-study-search-gws/ows?service=wms&version=1.1.1&request=GetCapabilities");

    //No Pop up, WORKS perfect
    //web::http::uri_builder uribuilder(L"http://demo.lizardtech.com/lizardtech/iserv/ows?SERVICE=WMS&REQUEST=GetCapabilities");

    http_client client(uribuilder.to_uri());

    client.request(methods::GET).then([=](http_response response){
        return response.body();
    }).then([=](concurrency::streams::istream is){
        concurrency::streams::streambuf<uint8_t> rwbuf = concurrency::streams::file_buffer<uint8_t>::open(fileName).get();
        is.read_to_end(rwbuf).get();
        rwbuf.close();
    }).wait();

    return 0;
}
Do you have another suggestion/code to get the information from the "pop up" server

Thanks in advance.
Coordinator
Feb 27, 2014 at 11:31 PM
Try this test code, set the breakpoint on the line "concurrency::streams::streambuf<uint8_t> rwbuf = concurrency::streams::file_buffer<uint8_t>::open(fileName).get();"
and debug it to see if the size of result vector is [size] = 0x0002ac7c
int _tmain(int argc, _TCHAR* argv [])
{
    auto fileName = L"D:\\sample.xml";

    // Pop up
    web::http::uri_builder uribuilder(L"http://www.ga.gov.au/flood-study-search-gws/ows?service=wms&version=1.1.1&request=GetCapabilities");
    http_client client(uribuilder.to_uri());

    client.request(methods::GET).then([=](http_response response){
        return response.extract_vector();
    }).then([=](std::vector<uint8_t> result){
        concurrency::streams::streambuf<uint8_t> rwbuf = concurrency::streams::file_buffer<uint8_t>::open(fileName).get();
        rwbuf.putn(&result[0], result.size()).wait();
        rwbuf.close();
    }).wait();

    return 0;
}
From my computer, I can save the xml file correctly.
Feb 28, 2014 at 12:10 AM
Hi zhelu, the size of the vector is 0 in my computer, so, the program launches a "Debug Assertion Failed" in "rwbuf.putn(&result[0], result.size()).wait();", because the vector is empty.

I'm working in Windows 7 Professional 64 bits, Visual Studio Professional 2013, and C++ REST SDK 1.4.0 (Not using anymore the nuget, so the debug process is easier). What is the configuration of your computer?, Do you have any clue what is not working in my computer?


Thanks in advance
Coordinator
Mar 4, 2014 at 5:21 PM
Hi,

I tried in Windows 7 Professional 64 bits, Visual Studio Professional 2013 and C++ REST SDK 1.4 from Nuget, t also works correctly.

Can you set the break point on the line "return response.extract_vector();" and debug to see what is the response header?

I need more information to investigate this problem.

Thanks
Mar 5, 2014 at 4:28 AM
Hi zhelu,

Here is the debug information for the response: Image

The header has information about the proxy here in my job, so, I ran the same project in my home, and all works perfect!. So, definetely, the problem is related with the router/proxy here in the office. But, if I use the browser here in the office, and in my home, I obtain the same response from the web server (the pop up).

Any help will be greatly appreciated.

Thanks
Mar 18, 2014 at 1:00 AM
Hi zhelu,

I've been doing some testing here, and I believe that the problem is related with https://casablanca.codeplex.com/discussions/470503 because the proxy here removes the Transfer-Encoding header.

There is a bug reported about this; https://casablanca.codeplex.com/workitem/80, but it's still in status "Proposed". Can you please increase the priority of it?

Thanks
Coordinator
Mar 18, 2014 at 1:14 AM
Hi,

We have a fix for this bug but in trouble of testing, since we cannot find any servers send response without Transfer-Encoding and Content-Length. If you are urgent, I can give you the fix code, you can compile the source code and test for us.

Thanks
Mar 18, 2014 at 1:22 AM
Hi,

yes, sure, I have here a proxy that just do that :).

Send me the code and I'll test it

Cheers!
Coordinator
Mar 18, 2014 at 4:17 AM
Mar 20, 2014 at 12:55 AM
It works perfect!!! :) , thanks for send me the code

A lot of thanks for all the help.

Best regards
Coordinator
Apr 4, 2014 at 2:01 AM
Hi azcar,

FYI this bug has been fixed in our 2.0.1 release that came out today.

Steve