这是微软的翻译API网址https://goo.gl/eCr0Dp
最近想了解翻译API,微软给的程式码贴上执行却是错的,会跑出
http://i.imgur.com/3gYPEjG.jpg
但我有加入system.dll,也是跑不出来
之后我再把最后一段原始程式码http://i.imgur.com/dB2xHLZ.jpg
改成
private AdmAccessToken HttpPost(string DatamarketAccessUri, string
requestDetails)
{
//Prepare OAuth request
WebRequest webRequest = WebRequest.Create(DatamarketAccessUri);
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Method = "POST";
byte[] bytes = Encoding.ASCII.GetBytes(requestDetails);
webRequest.ContentLength = bytes.Length;
try {
using (Stream outputStream = webRequest.GetRequestStream())
{
outputStream.Write(bytes, 0, bytes.Length);
}
using (WebResponse webResponse = webRequest.GetResponse())
{
DataContractJsonSerializer serializer = new
DataContractJsonSerializer(typeof(AdmAccessToken));
//Get deserialized object from JSON stream
AdmAccessToken token =
(AdmAccessToken)serializer.ReadObject(webResponse.GetResponseStream());
return token;
}
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
return null;
}
执行画面为http://i.imgur.com/pcGhbTF.jpg
请问我应该要如何改,脑袋已经打结了,希望大神们可以给我建议,谢谢。