wxHTTP. How to send data and read response

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
cutecode
Super wx Problem Solver
Super wx Problem Solver
Posts: 427
Joined: Fri Dec 09, 2016 7:28 am
Contact:

wxHTTP. How to send data and read response

Post by cutecode »

How to send data to a host and read response immediately?
I do it like this, but get.GetError() returns wxPROTO_NOFILE

Code: Select all

    wxHTTP get;
    get.SetHeader(_T("Content-type"), _T("application/soap+xml; charset=UTF-8"));
    get.SetTimeout(10); // 10 seconds of timeout instead of 10 minutes ...

    if(!get.Connect(_T("www.webservicex.net")))
        return false;

	if(!get.SetPostText(L"application/soap+xml; charset=UTF-8", L"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"))
	        return false;

    wxApp::IsMainLoopRunning();

    wxInputStream *httpStream = get.GetInputStream(_T("/ValidateEmail.asmx"));

    if (get.GetError() != wxPROTO_NOERR)
        return false;

    wxString res;
    wxStringOutputStream out_stream(&res);
    httpStream->Read(out_stream);

    wxDELETE(httpStream);
    get.Close();

    wxMessageBox(res);
wx 3.1.6 win/mac/linux

regards,
Alexander Saprykin
https://v2.dental-soft.ru
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxHTTP. How to send data and read response

Post by doublemax »

When i comment out the SetPostText() call, i get a response. I'm not sure yet if this is really a wxHTTP problem. Maybe it just because the data you're sending is incomplete?

I would suggest to test this with the command line version of Curl first. If that works, continue with wxHTTP. Or use libcurl right away.
Use the source, Luke!
Post Reply