C# 如何使用C在REST服务的json请求体中添加POST数据# private void CreateNewTasklist(字符串TasklistTitleValue) { AuthenticationProcess objUri=新的AuthenticationProcess(); if(string.IsNullOrEmpty(TasklistTitleValue)) { MessageBox.Show(“请输入任务列表标题”); } 其他的 { //在隔离存储中读取令牌结果。 string TokenResult=TasklistManager.ReadTokenResult(); var Token=Auth.ParseAuthJsonString(TokenResult); var request=new RestRequest(objUri.CreateTasklist,Method.POST); AddHeader(“内容类型”、“应用程序/json”); RestClient=新的RestClient(“https://www.googleapis.com"); client.Authenticator=新的OAuth2AuthorizationRequestHeaderAuthenticator(Token.access\u Token); client.ExecuteAsync(请求,任务列表已添加); } }
这里我得到字符串TasklistTitleValue的值。。我想把它寄出去。如何将其添加到请求体中,因为内容类型是application/json 您可以这样做:C# 如何使用C在REST服务的json请求体中添加POST数据# private void CreateNewTasklist(字符串TasklistTitleValue) { AuthenticationProcess objUri=新的AuthenticationProcess(); if(string.IsNullOrEmpty(TasklistTitleValue)) { MessageBox.Show(“请输入任务列表标题”); } 其他的 { //在隔离存储中读取令牌结果。 string TokenResult=TasklistManager.ReadTokenResult(); var Token=Auth.ParseAuthJsonString(TokenResult); var request=new RestRequest(objUri.CreateTasklist,Method.POST); AddHeader(“内容类型”、“应用程序/json”); RestClient=新的RestClient(“https://www.googleapis.com"); client.Authenticator=新的OAuth2AuthorizationRequestHeaderAuthenticator(Token.access\u Token); client.ExecuteAsync(请求,任务列表已添加); } },c#,windows-phone-7,windows-phone,C#,Windows Phone 7,Windows Phone,这里我得到字符串TasklistTitleValue的值。。我想把它寄出去。如何将其添加到请求体中,因为内容类型是application/json 您可以这样做: private void CreateNewTasklist(string TasklistTitleValue) { AuthenticationProcess objUri = new AuthenticationProcess(); if (string.IsNullOrEmpty(Ta
private void CreateNewTasklist(string TasklistTitleValue)
{
AuthenticationProcess objUri = new AuthenticationProcess();
if (string.IsNullOrEmpty(TasklistTitleValue))
{
MessageBox.Show("Please Enter the Tasklist Title.");
}
else
{
//Read the Token result in Isolated storage.
string TokenResult = TasklistManager.ReadTokenResult();
var Token = Auth.ParseAuthJsonString(TokenResult);
var request = new RestRequest(objUri.CreateTasklist, Method.POST);
request.AddHeader("content-type", "application/json");
RestClient client = new RestClient("https://www.googleapis.com");
client.Authenticator = new OAuth2AuthorizationRequestHeaderAuthenticator(Token.access_token);
client.ExecuteAsync<TasklistManager>(request, TaskListsLoaded);
}
}
或者,您可以使用:
那是一位客户吗?看起来这可能是以下内容的副本:
var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://url");
httpWebRequest.ContentType = "text/json";
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json = "{\"user\":\"test\"," +
"\"password\":\"bla"}";
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}