Last active
December 7, 2015 07:40
-
-
Save sheva29/9a90617128913baad066 to your computer and use it in GitHub Desktop.
oF GET/POST request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//GET request | |
//-------------------------------------------------------------- | |
void ofApp::getRequestToURL(){ | |
//This is what we will be posting to the | |
string getRequest = "http://localhost:8000/api/recommendations/?ids="; | |
//we pass the IDs to our string for the GET post | |
for ( int i = 0; i < suggestedProducts.size(); i++){ | |
getRequest += suggestedProducts[i]._id + ",";// I add my element's ID separated by a coma. | |
} | |
// cout << "We passed the URL" << endl; | |
int id = ofLoadURLAsync(getRequest,"state"); | |
} | |
//POST request | |
//-------------------------------------------------------------- | |
void ofApp::resetState(){ | |
string updateState = "{\"state\": \"interactive\" }"; | |
string cmd = "curl -X POST \ | |
-H \"Content-Type: application/json\" \ | |
-d '"+updateState+"' \ | |
http://localhost:8000/api/state"; | |
ofSystem( cmd ); | |
} | |
//Here I check my response from the server | |
//-------------------------------------------------------------- | |
void ofApp::urlResponse(ofHttpResponse &response){ | |
if (response.status == 200 && response.request.name == "state") { | |
cout << response.status << " " << response.data << endl; | |
} else { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment