這是微軟的翻譯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
請問我應該要如何改,腦袋已經打結了,希望大神們可以給我建議,謝謝。