Http file download, howto
Http file download, howto
Hea, does anyone have a sample code for connecting to a ap and downloading a file, i have the latest toolchain running on windows (dont ask lol), need urgently for a project
			
			
									
									
						Do you want a easy one with my libcurl+EasyConnect?
http://jojosoft.1free.ws/viewtopic.php?f=7&t=10
			
			
									
									http://jojosoft.1free.ws/viewtopic.php?f=7&t=10
Code: Select all
#include <pspkernel.h>
#include <pspdebug.h>
#include <stdio.h>
#include <curl/curl.h>
#include "easyconnect.h"
PSP_MODULE_INFO("Inet Sample", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
    sceKernelExitGame();
    return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
    int cbid;
    cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
    sceKernelRegisterExitCallback(cbid);
    sceKernelSleepThreadCB();
    return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
    int thid = 0;
    thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
    if (thid >= 0) {
        sceKernelStartThread(thid, 0, 0);
    }
    return thid;
}
size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) {
    FILE * pFile = fopen("tmp.tmp","w");
    size_t sizecontent = fwrite(buffer, size, nmemb, pFile);
    fclose(pFile);
    return sizecontent;
}
int main() {
    SetupCallbacks();
    EasyConnect connection;
    connection.InitGU();
    connection.Connect();
    connection.TermGU();
    pspDebugScreenInit();
    pspDebugScreenPrintf("Trying to download:\nhttp://www.google.com\n\n");
    if (connection.IsConnected()) {
        CURL *curl;
        CURLcode res;
        curl = curl_easy_init();
        if (curl) {
            curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com");
            curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
            res = curl_easy_perform(curl);
            curl_easy_cleanup(curl);
            if (res == CURLE_OK) {
                pspDebugScreenPrintf("File downloaded.\n\n\n");
                FILE * pFile = fopen("tmp.tmp","r+");
                long int size;
                fseek(pFile, 0, SEEK_END);
                size = ftell(pFile);
                rewind(pFile);
                char content[size + 1];
                memset(content,0,size+1);
                fread(content, size, 1, pFile);
                fclose(pFile);
                pspDebugScreenPrintf(content);
                
            } else {
                pspDebugScreenPrintf("Something went wrong with libcurl: error %i\n", res);
            }
            
        } else {
            pspDebugScreenPrintf("Something went wrong with libcurl\n");
        }
    } else {
        pspDebugScreenPrintf("You must connect to an access point to use this sample\n");
    }
    while (1) {
        sceKernelDelayThread(10000);
    }
    sceKernelExitGame();
    return 0;
}Code: Select all
int main(){
     SetupCallbacks();
     makeNiceGame();
     sceKernelExitGame();
}zlib error
Looking for help, I got problem when try to do make.
And Makefile
Thanks!
			
			
									
									
						Code: Select all
/usr/local/pspdev/lib/gcc/psp/4.3.2/../../../../psp/lib/libcurl.a(content_encodi
ng.o): In function `exit_zlib':
content_encoding.c:(.text+0xa0): undefined reference to `inflateEnd'
/usr/local/pspdev/lib/gcc/psp/4.3.2/../../../../psp/lib/libcurl.a(content_encodi
ng.o): In function `inflate_stream':
content_encoding.c:(.text+0x164): undefined reference to `inflate'
content_encoding.c:(.text+0x23c): undefined reference to `inflateEnd'
/usr/local/pspdev/lib/gcc/psp/4.3.2/../../../../psp/lib/libcurl.a(content_encodi
ng.o): In function `Curl_unencode_deflate_write':
content_encoding.c:(.text+0x3c0): undefined reference to `inflateInit_'
/usr/local/pspdev/lib/gcc/psp/4.3.2/../../../../psp/lib/libcurl.a(content_encodi
ng.o): In function `Curl_unencode_gzip_write':
content_encoding.c:(.text+0x7cc): undefined reference to `zlibVersion'
content_encoding.c:(.text+0x804): undefined reference to `inflateInit2_'
content_encoding.c:(.text+0x858): undefined reference to `inflateInit2_'
collect2: ld returned 1 exit status
make: *** [myproject.elf] Error 1
Code: Select all
TARGET = myproject
OBJS = main.o easyconnect.o
INCDIR = 
CFLAGS = -G0 -Wall -O2
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LIBS= -lstdc++ -lpspgu -lz -lcurl
BUILD_PRX=1
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = My PSP Project
BUILD_PRX = 1
PSP_FW_VERSION = 371
PSP_LARGE_MEMORY = 1
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
I guess the order is wrong (but -lz is correct): A library which depends on other has to be linked before the libraries it depends on. So, it should be :
			
			
									
									
						Code: Select all
-lcurl -lzYES, IT WORKS!
Thanks Mon Ouïe!
			
			
									
									
						Thanks Mon Ouïe!
Mon Ouïe wrote:I guess the order is wrong (but -lz is correct): A library which depends on other has to be linked before the libraries it depends on. So, it should be :Code: Select all
-lcurl -lz