0

I am trying to connect to an API that has given me the log in example of:

 POST /api/login  
 Host: nephele.qtestnet.com  
 Cache-Control: no-cache  
 Content-Type: application/x-www-form-urlencoded  
 j_username= maxmccloud%40qasymphony.com&j_password=p@ssw0rd  

I tried to implement this as:

class QTestDriver
{
    HttpClient http = new HttpClient();
    public QTestDriver()
    {
        http.BaseAddress = new Uri("http://ahpra.testnet.com");
    }

    public async void Login()
    {
        HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "/api/login");
        request.Headers.CacheControl = new CacheControlHeaderValue() { NoCache = true };
        request.Content = new StringContent("j_username=scott&j_password=xxxx", Encoding.UTF8, "application/x-www-form-urlencoded");
        HttpResponseMessage resp = await http.SendAsync(request);
    }
}

However the response I get is

"StatusCode: 463, ReasonPhrase: 'Unknown', Version: 1.0, Content: System.Net.Http.StreamContent, Headers:\r\n{\r\n  X-Cache: MISS from webtitan\r\n  Proxy-Connection: close\r\n  Date: Fri, 20 Mar 2015 05:04:32 GMT\r\n  ETag: \"5501c94b-19c4\"\r\n  Server: nginx/1.7.9\r\n  Via: 1.0 webtitan (squid/3.0.STABLE26)\r\n  Content-Length: 6596\r\n  Content-Type: text/html\r\n}"    string

I have googled this but can't find anything useful about Status 463.

1
  • FYI, HttpClient is part of .NET, not part of C#. Commented Mar 20, 2015 at 5:11

1 Answer 1

1

That's a very odd response, and I stongly suspect the problem is on the API provider's end. When you see a status code that's not listed on the Wikipedia page, which goes so far as to include 418 (I'm a teapot), it's a safe bet something's wrong on their end.

I'm not spotting anything wrong with your code, but to leave less room for error I'd consider using FormUrlEncodedContent instead of StringContent. You might even consider using my Flurl.Http library, which would reduce the whole call to something like this:

var resp = await "http://ahpra.testnet.com/api/login"
    .WithHeader("cache-control", "no-cache")
    .PostUrlEncodedAsync(new {
        j_username = "scott",
        j_password = "xxxx"
    });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.