0
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);
        }
    }

ここで文字列TasklistTitleValue値を取得します..POSTしたいです。content-typeがapplication/jsonであるため、リクエスト本文に追加する方法。

4

1 に答える 1

0

あなたはこれを行うことができます:

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();
}

またはこれを使用できます:

https://github.com/ademargomes/JsonRequest

于 2012-07-20T13:52:20.533 に答える