Sylvia
Sylvia

Reputation: 23

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?

Upvotes: 1

Views: 790

Answers (1)

0x0000000000000
0x0000000000000

Reputation: 166

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

Upvotes: 4

Related Questions