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

New Post: Trying to Replicate a Post make from the Chrome REST Console to Prosper.com using the REST SDK

$
0
0
Hello,

I am trying to create a program to interface with the API of the peer-to-peer lending site, Prosper.com. I am able to successfully post a loan request from the REST Console of Chrome, but I am unable to duplicate this request within my C++ program and I'm hoping someone can help identify my mistake(s).

Here are the parameters I entered into the REST Console:

Request URI: https://api.prosper.com/api/Invest/
Request Method: POST
Request Timeout: 60 seconds
Content-Type: application/x-www-form-urlencoded
Request Parameters:
amount, 25.00
listingId, 2430877
Authorization Header: Basic EncodedStringHere

When I clicked the "Send" button, I received a response that the request was a success and the loan was made. Here is the request header reported by the REST Console:

Content-Type: application/x-www-form-urlencoded
Authorization: Basic EncodedStringHere
Accept: /
Connection: keep-alive
Origin: chrome-extension: //rest-console-id
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36

and here is the request body:

Request Url: https://api.prosper.com/api/Invest/
Request Method: POST
Status Code: 200
Params: {
"amount": "25.00",
"listingId": "2430877"
}

So I figured that if I could just duplicate this header and body from within my C++ program, that it would also work, but I get a return code of 400. Here is my code:
http_client client(U("https://api.prosper.com"));
http_request req(methods::POST);
req.set_request_uri(U("api/Invest"));
req.headers().add(header_names::authorization, U("Basic EncodedStringHere"));
req.headers().add(header_names::content_type, U("application/x-www-form-urlencoded"));
req.headers().add(header_names::connection, U("keep-alive"));
req.headers().add(header_names::accept, U("*/*"));
wchar_t parmString[] = L"Params: {\n   \"listingId\": \"2430877\",\n   \"amount\": \"25.00\"\n}";
wchar_t bodyString[1000];
swprintf(bodyString,L"Request Url: https://api.prosper.com/api/Invest/\nRequest Method: POST\nStatus Code: 200\n%s",parmString);
req.set_body(bodyString);
http_response response = client.request(req).get();
if(response.status_code() == status_codes::OK)
{
  auto body = response.extract_string();    
  AfxMessageBox(CString(body.get().c_str()));
}
else {
    CString errorString;
    errorString.Format("Error Code: %d", response.status_code());
    AfxMessageBox(errorString);
    AfxMessageBox(CString(bodyString));
} 
The last line displays the body, which I have confirmed is identical to the body reported by the REST Console.

Any help would be greatly appreciated.

Gary

Viewing all articles
Browse latest Browse all 4845

Trending Articles



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