I am trying to mess around with mobile development using Marmalade SDK. I am currently trying to accomplish various tasks using IwHTTP. I have been able to replicate my particular problem on the http://www.google.com URL. What happens is that my code will output the source code for a "302 error" page instead of the standard Google page. This is not my specific problem (i.e. I could not care less about Google) but this replicates my issue with another website.

I have tried to look around the web to find about this issue but only found issues related to malware. I do not think this is an issue of using the library. This is most probably my lack of understanding of HTTP that is biting me here. Here is the short snippet that will produce this error.

#include "s3e.h"
#include "IwGx.h"
#include "IwHTTP.h"
#include <string>

int32 rec = 0;
CIwHTTP http;
std::string output = "";
char buffer[1024];

int32 min(int32 a, int32 b) { return a > b ? b : a; }

int32 http_get_callback(void* sys_data, void* user_data) {
    if(http.ContentReceived() < http.ContentLength()) {
        http.ReadData(buffer, min(1024, http.ContentLength() - http.ContentReceived()));
        output += buffer;
    }
}

int main()
{
    IwGxInit();

    IwGxSetColClear(0, 0, 0xff, 0xff);

    http.Get("https://www.google.com", http_get_callback, 0);

    while(!s3eDeviceCheckQuitRequest() && 
            !s3eKeyboardGetState(s3eKeyEsc) & S3E_KEY_STATE_DOWN &&
            !s3eKeyboardGetState(s3eKeyAbsBSK) & S3E_KEY_STATE_DOWN)
    {
        IwGxClear();
        IwGxPrintString(5, 5, output.c_str());
        IwGxFlush();
        IwGxSwapBuffers();
        s3eDeviceYield(0);
    }
    IwGxTerminate();
    return 0;
}

I have also tried variants (with or without SSL, with .com and .ca) and I could not get the expected output.

Any pointer on this issue ?

Edit: And I do know this code is most probably horrible, this is just test code to learn the SDK.

有帮助吗?

解决方案

HTTP code 302 means a temporary redirect. For a browser, it means you're supposed to follow the redirect. The place to redirect to is in the HTTP response header as Location:.

If you want to use this redirect, you'll need to get this header and follow it.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top