简体   繁体   中英

How debug 401 unauthorized error?

I want to post json to the server, I created json and passing it. But getting The remote server returned an error: (401) Unauthorized error. Can some one help me with that.

I have posted my code:----------------------------------------------------------

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

I have posted required fields below:--------------------------------------------

Request Headers requires:-

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

Request Data:- only email, full name, phonenumber and ip_address, client id and client secrate is mandatory This is accepted input, from their website.

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

I dont know what i am doning wrong..

and this is the API I am using.

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

You are getting an email already exists error.

You need to check the response and look at the "success flag & reason.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM