c# - Can't return HTTP status and data from a method after using httpClient.GetAsync() -
i having issues following code. retrieving json object string , wish return method can used elsewhere. when message:
'filmsglossary.searchqueries.returnjson(object); returns void, return keyword must not followed object expression'
public async void returnjson(object term) { //set variables var searchformat = "&format=json"; var termvalue = term; var httpclient = new httpclient(); try { //set web service url format string baseuri = "http://localhost/filmgloss/webservice/web-service.php?termname="; string useruri = baseuri + termvalue + searchformat; //send url web service , retrieve response code. var response = await httpclient.getasync(useruri); response.ensuresuccessstatuscode(); var content = await response.content.readasstringasync(); return content.tostring(); } catch (httprequestexception hre) { } catch (exception ex) { } }
originally returning
return content;
however after reading seemed issue might needed change to:
return content.tostring();
however did not help. read change synchronous, rather asynchronous method , change method 'public string' learning c# , don't yet understand implications of (or how it).
is possible resolve error within code have?
i understand cause of issue rather know solution.
thanks.
you should paste error messages getting.
why function declaration return void
? should return task<string
>.
public async task<string> returnjson(object term)
also in body should return task, this:
await response.content.readasstringasync();
Comments
Post a Comment