我不好说英语
继承我的问题,
我是第一次用c#编程,我正在写一个论坛作为一个应用程序,所以你可以看到线程,你可以发布。所以从管理员我知道我必须对特定的URL进行Http-Request。使用参数:登录名和密码。并且操作是登录。此外,我必须保存哈希并将其用于下一个请求。有人可以帮我解决这个问题吗?
namespace PhoneApp8
{
public partial class Login{
public async Task<string> SendJSONData(string https://xxxx.xxxx.xxx, string JSONData)
{
// server to POST to
string url = https://xxxx.xxxxx.xxxxx;
// HTTP web request
var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.ContentType = "action";
httpWebRequest.Method = "POST";
// Write the request Asynchronously
using (var stream = await Task.Factory.FromAsync<Stream>(httpWebRequest.BeginGetRequestStream,
httpWebRequest.EndGetRequestStream, null))
{
//create some json string
string json = JSONData;
// convert json to byte array
byte[] jsonAsBytes = Encoding.UTF8.GetBytes(json);
// Write the bytes to the stream
await stream.WriteAsync(jsonAsBytes, 0, jsonAsBytes.Length);
}
WebResponse response = await httpWebRequest.GetResponseAsync();
StreamReader requestReader = new StreamReader(response.GetResponseStream());
String webResponse = requestReader.ReadToEnd();
return webResponse;
}
public partial class MainPage : PhoneApplicationPage
{
// Konstruktor
public MainPage()
{
InitializeComponent();
// Beispielcode zur Lokalisierung der ApplicationBar
//BuildLocalizedApplicationBar();
}
}