简体   繁体   中英

The server returned an invalid or incomplete HTTP response

I have trouble with OAuth 2 authentication my app in .Net. I'm creating an integration between BigCommerce and SmartPablo. Single click app authorization and authentication occurs via OAuth2 authorization code grant.

Part of my Code:

HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "https://login.bigcommerce.com/oauth2/token");
Dictionary<string, string> body = new Dictionary<string, string>()
{
    {"client_id", "clientId"},
    {"client_secret", "clientSecret"},
    {"redirect_uri", baseUrl + "/auth/install"},
    {"grant_type", "authorization_code"},
    {"code", query["code"]},
    {"scope", query["scope"]},
    {"context", query["context"]}
};

request.Content = new FormUrlEncodedContent(body);
HttpResponseMessage response = await _clientFactory.CreateClient().SendAsync(request);

Can someone please help me?

I highly recommend that you use a utility like Postman to test your API endpoint.

Without knowing the data schema necessary for the API to work, finding the problem could be complicated.

Also after testing the API with PostMan if the C # code is problematic while PostMan succeeds, you should sniff the requests to find the problem (s) and fix them

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