After many years of inactivity, I've decided to try my hand at programming again.
To the point: I've been working on a simple HTTP GET request to youtube, attempting to get an XML document through their fairly simple API. When I go to use wxHTTP::GetInputStream though, I get (with certain regularity) a Segmentation fault.
Code below:
Code: Select all
wxString wxGETRequest(wxString pageDir)
{
wxString response = wxEmptyString;
wxHTTP request;
request.Connect(wxT("gdata.youtube.com"));
wxInputStream *serverStream = request.GetInputStream(pageDir);
if(request.GetError() == wxPROTO_NOERR)
{
wxStringOutputStream outputStream(&response);
serverStream -> Read(outputStream);
}
else response = wxEmptyString;
wxDELETE(serverStream);
request.Close();
return response;
}
int main()
{
string Query;
wxString wxQuery;
wxString wxQueryURI;
cout << "Enter search term: ";
getline(cin, Query);
wxQuery = wxQuery.FromAscii(Query.c_str());
wxQuery.Replace(wxT(" "), wxT("+"), true);
wxQueryURI = wxT("/feeds/api/videos?q=") + wxQuery + wxT("&max-results=10&v=2");
cout << endl << wxQueryURI.ToAscii() << endl << endl;
wxString searchResponseString = wxGETRequest(wxQueryURI);
cout << endl << searchResponseString << endl;
}
Program output:
Thanks for the help!Enter search term: test
/feeds/api/videos?q=test&max-results=10&v=2
Segmentation fault
FlyingIsFun1217