如何调试401未授权错误?

时间:2015-06-01 20:58:41

标签: c# asp.net .net json asp.net-web-api

我想将json发布到服务器,我创建了json并传递它。但是获取远程服务器返回错误:(401)未经授权的错误。有人可以帮助我。

我发布了我的代码:----------------------------------------- -----------------

    var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://synapsepay.com/api/v2/user/create");
    httpWebRequest.ContentType = "application/json";
    httpWebRequest.Method = "POST";

    using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
    {
        string json = "{\"email\":\"nikunj@synapsepay.com\"," +
                      "\"fullname\":\"nik\"," +
                      "\"phonenumber\":\"111\"," +
                      "\"ip_address\":\"1.1.1.1.1\"," +
                      "\"password\":\"123123123\"," +
                      "\"client_id\":\"116db45feb835d2cd5d2\"," +
                      "\"client_secret\":\"ba1c5db06d50d047ac294f4acb31cf0958bcfdf6\"}";

        streamWriter.Write(json);
        streamWriter.Flush();
        streamWriter.Close();
    }

    var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
    {
        var result = streamReader.ReadToEnd();
    }
}

我已经发布了以下必填字段:---------------------------------------- ----

请求标题需要: -

Accept: */*
Content-Type: application/json
accept-encoding: gzip
content-length: 280

请求数据: - 只有电子邮件,全名,phonenumber和ip_address,客户端ID和客户端密码是强制性的 这是他们网站上接受的输入。

{
    "email": "nikunj625@gmail.com",
    "fullname": "nikunj mange",
    "phonenumber": "4089170880",
    "ip_address": "1.1.1.1.1",
    "dp": "a",
    "password": "123123",
    "client_id": "@@@@@@@@@@@@@@@@@",
    "client_secret": "#######################################"
}

我不知道我做错了什么..

这是我正在使用的API。

http://api.synapsepay.com/v2.0/docs/create-a-usercustomer

1 个答案:

答案 0 :(得分:1)

您收到的电子邮件已存在错误。

您需要检查回复并查看“成功标志和原因。

enter image description here