Quantcast
Channel: WE MOVED to github.com/microsoft/cpprestsdk. This site is not monitored!
Viewing all articles
Browse latest Browse all 4845

New Post: Assert with request in http_client_impl.h on iOS

$
0
0
I am attempting to use the SDK in iOS 8, and it is failing an assert in http_client_impl.h upon the second attempt to connect.
I create a, http_client as a class member, and use it to issue a single request per class instance. The second time I create an instance of this class and issue a request, the assertion fails. Below is the assertion (line 172, http_client_impl.h):
virtual concurrency::streams::streambuf<uint8_t> _get_readbuffer()
    {
        auto instream = m_request.body();

        _ASSERTE((bool)instream);
        return instream.streambuf();
    }
Here is an example of the code making the request:
using namespace web;
using namespace web::http;
using namespace web::http::client;
using namespace std;


pplx::task<http_response>
Request::connect()
{

    //Should be set to GET, POST, PUT, or DELETE
    if (HTTPMethod.length() == 0)
    {
        HTTPMethod = methods::GET;
    }
    
    http_request req(HTTPMethod);
    
    if (HTTPBody.length() > 0)
    {
        std::string val;
        formatString(val, "%zd",HTTPBody.length());
        req.headers().add(header_names::content_length,val);
    }
    
    map<string,string>::const_iterator it;
    for (it = HTTPHeaders.begin(); it != HTTPHeaders.end(); it++) {
        const std::string header = (*it).first;
        const std::string value = (*it).second;
        req.headers().add(header,value);
    }

    //client is set with the URI
    req.set_request_uri("");
    return client.request(req);
    
}


void
Request::connectSync(Response& response)
{

    logInfo("connectSync: url (%s)", URL.c_str());

    try {
    
        http_response resp;
        
        connect().then([&](pplx::task<http_response> prevTask)
        {
        
            auto res = prevTask.get();
            logInfo("Result (%s) Requested URL (%s)", res.reason_phrase().c_str(), URL.c_str());
            resp = res;

        }).wait();
        
        response.body = resp.extract_string().get().c_str();
        response.httpCode = resp.status_code();

    } catch (http_exception &e) {
    
        logError("Error (%s) Requested URL (%s)", e.what(), URL.c_str());
        throw e;

    }
    
}
I am new to this, but based on the examples and documentation I have read, this should work. Any ideas??

Viewing all articles
Browse latest Browse all 4845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>