0
我想聯繫一個簡單的登錄Web服務,將確定是否JSON請求是否成功。目前,在C#程序中,我產生了一個錯誤,指出缺少JSON參數。正確的URL在Web瀏覽器的要求是:如何正確發佈到php web服務使用JSON和C#
https://devcloud.fulgentcorp.com/bifrost/ws.php?json=[{"action":"login"},{"login":"demouser"},{"password":"xxxx"},{"checksum":"xxxx"}]
,我已經在C#實現,現在的代碼是:
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Web.Script.Serialization;
namespace request
{
class MainClass
{
public static void Main (string[] args)
{
var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://devcloud.fulgentcorp.com/bifrost/ws.php?");
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json = new JavaScriptSerializer().Serialize(new
{
action = "login",
login = "demouser",
password = "xxxx",
checksum = "xxxx"
});
Console.WriteLine ("\n\n"+json+"\n\n");
streamWriter.Write(json);
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
Console.WriteLine (result);
}
}
}
}
啊好吧謝謝這就是它。我查找了GET請求,並從微軟找到了一個很好的樣例。再次感謝 – MeesterMarcus
沒有probs。謝謝你的勾號。 – Patrick