1

我正在 Parse Cloud 中尝试这个 POST 函数,并使用 http 响应代码 302 抛出错误。谁能告诉我如何解决这个问题?

Parse.Cloud.httpRequest({
        method: 'POST',
        url: 'http://siteabcd.com/auth.action',
        body: {
            username: 'user',
            password: 'pass',
            button: 'Login',
        },  
        headers: {
            'User-Agent' : "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2"
        },
        success: function(httpResponse){
            alert("response:"+httpResponse.text+"---header length:"+httpResponse.headers.length);
                response.success("Message Sent");
        },
        error: function(httpResponse){
        console.error('Request failed with response code ' + httpResponse.status);
            response.error("Message Not Sent");
        }
    });
4

2 回答 2

2

As @dimitri points out 302 means redirect. For example if you go to http://google.com in Sweden Google will most likely send a 302 response at first and then go to http://google.se. It could also be that the domain redirects from http version to a https or similar.

Parse doesn't support redirects yet in their sdk. The easiest way to solve this until they do is to look at the Location header in the 302 response res.get('Location'); and update the url you are sending the request to accordingly.

于 2016-01-06T16:54:40.857 回答