C# api responce and request -
i have code
try { string url = "http://myanimelist.net/api/animelist/update/" + "6.xml"; webrequest request = webrequest.create(url); request.contenttype = "xml/text"; request.method = "post"; request.credentials = new networkcredential("username", "password"); byte[] buffer = encoding.getencoding("utf-8").getbytes("<episode>4</episode>"); stream reqstr = request.getrequeststream(); reqstr.write(buffer, 0, buffer.length); reqstr.close(); messagebox.show("updated"); } catch (exception s) { messagebox.show(s.message); }
i trying send data myanimelist.net code have written this
url: http://myanimelist.net/api/animelist/update/id.xml formats: xml http method(s): post requires authentication:true parameters: id. required. id of anime update. example: http://myanimelist.net/api/animelist/update/21.xml data. required. parameter specified 'data' must passed. must contain anime values in xml format. response: 'updated' or detailed error message.
the usage code example have stated this, know how in c# or wrong original code?
usage examples: curl: curl -u user:password -d data="xml" http://myanimelist.net/api/animelist/update/21.xml
edit: when lauch myanimelist.net shows has not been updated, sure username , password credentials correct
edit 2 : have added response comes error "the remote server returned error: (501) not implemented."
you're not performing request, once you're done writing request stream itself, perform actual web request:
string result; using (httpwebresponse response = (httpwebresponse)request.getresponse()) { using (streamreader reader = new streamreader(response.getresponsestream())) { result = reader.readtoend(); } }
also, content type should text/xml
or application/xml
- api may complaining that. read documentation api , ensure you're sending correct.
Comments
Post a Comment