Webrequest 504 Gateway Timeout

Asked

Viewed 876 times

2

Eai guys, I’m having a hard time understanding why is giving gateway timeout in a request, since I tested by Curl and was normal, I’m using Basic Auth. Follows:

            var authorization = "apikey:";
            HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.Create("https://api.konduto.com/v1/orders/0");            
            ServicePointManager.ServerCertificateValidationCallback += delegate { return true; };            
            wbRequest.Headers["Authorization"] = string.Format("Basic {0}", authorization);
            wbRequest.Method = "GET";                  
            var response = (HttpWebResponse)wbRequest.GetResponse();
            var stringFinally = "";
            using (var reader = new StreamReader(response.GetResponseStream()))
            {
                stringFinally = reader.ReadToEnd();
            }

When I give getresponse it comes back to me :

The remote server returned an error: (504) Gateway Timeout.

I wonder if anyone has already been through this and how I could solve, because via Curl the GET works normal.

  • wbRequest.Timeout = timeout; should work.

  • The problem seems to be the location accessed (maybe you have some difficulty because of your internet). The timeout default is 100 seconds, I already think a lot. It may be the way to use but only with this information can not know. The code seems to be okay with this (as always most of the codes posted here do not do everything they should to be robust, but this is something else). Have you tried to access without this code? I have my doubts if this authorization is necessary. I used with nothing and was.

  • I tried to do a test, I don’t know if there is any problem with the environment I have but if I access in the browser without passing an API key returns an immediate result. Without trying for code without authorization, it gives authorization error. It doesn’t make much sense since the browser works. And really when you put the authorization he can’t return anything in a timely manner. This indicates that this type of authorization is causing a problem. See the documentation for any other way to do this. It is complicated to answer questions about very specific Apis.

  • @Wisneroliveira erases this quickly. Unless this is temporary, don’t worry (even) about posting private information on the Internet. With Curl do you pass this key to and do the authorization process or not? This looks like their problem or misuse of the API, I don’t know if anyone here could help. They provide support?

  • @bigown a key is temporary, I revoke it and I get another and yes I pass via Curl too, follow script: Curl -u "apikey" -X GET "https://api.konduto.com/v1/orders/0"

  • Ever tried to use HTTPClient?

  • @bigown yes, I’ve tried.

  • @bigown the return when exiting by Curl comes like this : {"status":"error","message":{"Where":"/","Why":{"expected":"order (0) to exist","found":"order (0) does not exist"}} certinho

  • It’s what I got for the browser without authorization, without anything. That’s why it’s weird. Because I think there is something wrong with using the API, you probably have to pass something else to work. But on the other hand it should work without authorization too, it works in the browser.

  • @bigown serious ? o. what return you get by browser ? the only return I get from the browser is this : {"status":"error","message":{"Where":"/","Why":{"expected":"Authentic API key." ,"found":"Unauthentic API key."}}}

  • 1

    True, I’d forgotten. But in te this is a real return, it’s not a browser authorization error. Only you know what to do with it, the navigator doesn’t. Of course there may also be an authorization error I haven’t seen (I can’t see it now). I still think you’ll need specific support to see what’s left to send. But I have no experience with these components, so there might be an obvious problem that I’m not realizing.

  • I get it, I’m going to look for API support and see if there’s anything missing, thank you very much for your attention.

Show 8 more comments

1 answer

2

Resolved as follows:

var authorization = "apikey:";
HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.Create("https://api.konduto.com/v1/orders/0");
wbRequest.Credentials = CredentialCache.DefaultCredentials;
ServicePointManager.ServerCertificateValidationCallback += delegate { return true; };

string apiKey = Convert.ToBase64String(UTF8Encoding.UTF8.GetBytes(authorization));
wbRequest.Headers["Authorization"] = string.Format("Basic {0}", apiKey);
wbRequest.Method = "GET";
try
{
    var response = (HttpWebResponse)wbRequest.GetResponse(); 
    var stringFinally = "";
    using (var reader = new StreamReader(response.GetResponseStream()))
    {
        stringFinally = reader.ReadToEnd();
    }
 }
 catch (WebException ex)
 {
     var stringFinallyException = "";
     using (var reader = new StreamReader(ex.Response.GetResponseStream()))
     {
          stringFinallyException = reader.ReadToEnd();
     }
 }

I played the key API to Base64. The mistake 504 gateway timeout is that the request has not yet been validated because the basic Auth was going pure kind XYZXYZXYZX: and he has to go on Base64.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.