rewon
rewon

Reputation: 593

Parse response 124, timed out for simple GET request

For the life of me I can't figure this out. I have the following code up on Parse.com:

Parse.Cloud.httpRequest({
  method: "GET",
  url: 'http://www.csse.monash.edu.au/~jwb/cgi-bin/wwwjdic.cgi?9ZIG%EF%BC%B0%EF%BC%B2%EF%BC',
  success: function(httpResponse) {
      response.success(httpResponse.text);
  },
  error: function(httpResponse) {
      response.error('Request failed with response ' + httpResponse.status);
  }
});

It's a simple GET request, but it hangs and after about 10 seconds, Parse.com will time out with error 124: Request Timed Out.

If I substitute https://www.google.com or https://parse.com, it will deliver me the results instantaneously. So, I thought it might be the page I'm trying to load, but I can access http://www.csse.monash.edu.au/~jwb/cgi-bin/wwwjdic.cgi?9ZIG%EF%BC%B0%EF%BC%B2%EF%BC on my browser and it loads pretty much instantaneously.

The request also loads pretty much instantaneously when I use cURL:

curl -v http://www.csse.monash.edu.au/~jwb/cgi-bin/wwwjdic.cgi?9ZIG%EF%BC%B0%EF%BC%B2%EF%BC


* Adding handle: conn: 0x7fcb0c800000
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fcb0c800000) send_pipe: 1, recv_pipe: 0
* About to connect() to www.csse.monash.edu.au port 80 (#0)
*   Trying 130.194.64.145...
* Connected to www.csse.monash.edu.au (130.194.64.145) port 80 (#0)
> GET /~jwb/cgi-bin/wwwjdic.cgi?9ZIG%EF%BC%B0%EF%BC%B2%EF%BC HTTP/1.1
> User-Agent: curl/7.30.0
> Host: www.csse.monash.edu.au
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Sun, 21 Sep 2014 02:30:23 GMT
* Server Apache/1.3.26 (Unix) mod_layout/3.0.4 mod_ssl/2.8.10 OpenSSL/0.9.6e is not blacklisted
< Server: Apache/1.3.26 (Unix) mod_layout/3.0.4 mod_ssl/2.8.10 OpenSSL/0.9.6e
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=UTF-8
< 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><TITLE>WWWJDIC: Text/word translation display</TITLE>
</HEAD><BODY>
<br>
<FONT color="red">PR</FONT>。<br>
<ul><li> PR 【ピーアール】   (n) (See パブリックリレーションズ) public relations; PR; ED </li>
</ul><br>
</BODY>
</HTML>
* Connection #0 to host www.csse.monash.edu.au left intact

I feel like I must be missing something really simple. I added all the headers and none seemed to make a difference. Does anyone have an idea?

Upvotes: 0

Views: 1841

Answers (1)

Wes Blackmore
Wes Blackmore

Reputation: 11

OK I've worked this out and it's taken me HOURS. Firstly Parse will not accept httpRequests outside of Cloud Code beforeSave, afterSave and cloud functions. You will also have to use a Parse Promise.

So in main.js in your Cloud Code setup create the function testParse like this:

Parse.Cloud.define("testParse", function(request, response) {

    var promises = [];

    promises.push(Parse.Cloud.httpRequest({
        method: "GET",
        url: 'http://www.csse.monash.edu.au/~jwb/cgi-bin/wwwjdic.cgi?9ZIG%EF%BC%B0%EF%BC%B2%EF%BC'
    });

    Parse.Promise.when(promises).then(function(results) {
       response.success(results.status);
    }, function(error) {
        response.error(error);
    });
});

To call the function you will use

Parse.Cloud.run('testParse');

This solution works. Frustrating though, only 10% of the time. I still get timeouts.

Edit: OK got it to work. On the Parse.Cloud.define error response call the function again:

Parse.Promise.when(promises).then(function(results) {
    response.success(results.status);
}, function(error) {
    Parse.Cloud.run('testParse');
}); 

Upvotes: 1

Related Questions