Hello,
I am creating a program that connects to the internet to download files. I am trying to download a file from the program, but httpcInit() returns -522183694 and httpcOpenContext() returns -656406537. I am connected to the Internet when I run the program. Here is my code:
What is wrong with my program? If you need anything else, just ask me.
I am creating a program that connects to the internet to download files. I am trying to download a file from the program, but httpcInit() returns -522183694 and httpcOpenContext() returns -656406537. I am connected to the Internet when I run the program. Here is my code:
Code:
//
// main.cpp
// Homebrew Manager
//
// Created by JackMacWindows on 1/15/16.
// Copyright © 2016 MCJack123. All rights reserved.
//
#include "utils.h"
#include "parser.h"
#include "execute.h"
Result ret = 0;
u8 *packagesF;
httpcContext context;
char *url = "http://raw.githubusercontent.com/MCJack123/HBM-repo/master/Packages";
//from utils.h
u8 * http_download(httpcContext *context) { //This error handling needs updated with proper text printing once ctrulib itself supports that.
Result ret = 0;
u32 statuscode = 0;
u32 contentsize = 0;
u8 *buf;
ret = httpcBeginRequest(context);
if (ret != 0) {debugPrint("\x1b[31mFailed to connect: request denied\x1b[37m"); return (u8*)"";}
ret = httpcGetResponseStatusCode(context, &statuscode);
if (ret != 0) {debugPrint("\x1b[31mFailed to connect: could not get status code\x1b[37m"); return (u8*)"";}
if (statuscode != 200) {
#ifdef __DEBUG
printf("\x1b[31mError: Failed to connect: Bad status code (%lu %s)\x1b[37m\n", statuscode, httpResponses[statuscode]);
#endif
return (u8*)"";
}
ret=httpcGetDownloadSizeState(context, NULL, &contentsize);
if (ret != 0) {debugPrint("\x1b[31mFailed to connect: could not get size\x1b[37m"); return (u8*)"";}
gfxFlushBuffers();
buf = (u8*)malloc(contentsize);
if (buf == NULL) {debugPrint("\x1b[31mError: could not allocate memory\x1b[37m"); return (u8*)"";}
memset(buf, 0, contentsize);
ret = httpcDownloadData(context, buf, contentsize, NULL);
if (ret != 0) {
debugPrint("\x1b[31mFailed to connect: failed to download file\x1b[37m");
free(buf);
return (u8*)"";
}
return buf;
}
//done
int main(int argc, char* argv[]) {
gfxInitDefault();
//Initialize console on top screen. Using NULL as the second argument tells the console library to use the internal console structure as current one
consoleInit(GFX_TOP, &screen);
consoleInit(GFX_BOTTOM,&debug);
consoleSelect(&screen);
APT_CheckNew3DS(&consoletype);
printf("Console type: %s\n",consoletype?"New 3DS. Good job!":"Old 3DS. This may be a bit slow.");
debugPrint("Downloading packages file");
consoleSelect(&debug);
printf("%li ", httpcInit(256)); //httpcInit() returns -522183694
ret = httpcOpenContext(&context, HTTPC_METHOD_GET, url, 1); //returns -656406537
printf("%li", ret);
consoleSelect(&screen);
if (ret == 0) {
debugPrint("Starting download");
packagesF = http_download(&context);
debugPrint((const char*)packagesF);
parsePackagesFile(std::string((char*)packagesF));
httpcCloseContext(&context);
debugPrint("Done.");
} else printf("\x1b[31mError: Failed to connect\x1b[37m\n");
int selection = 0;
consoleSelect(&screen);
while (aptMainLoop()) {
consoleClear();
printf("Homebrew Manager for 3DS by JackMacWindows\nPlease select an option:\n\n %s Install official package\n %s Add/install unofficial repository\n %s Download other zip file", selection==0?"*":" ", selection==1?"*":" ", selection==2?"*":" ");
hidScanInput();
u32 kDown = hidKeysDown();
if (kDown) {
if (kDown & KEY_DOWN) selection = incIntWithMax(selection, 2);
else if (kDown & KEY_UP) selection = decIntWithMax(selection, 2);
else if (kDown & KEY_A) {
consoleClear();
printf("\n\nSelected option: ");
runManager(selection);
}
else if (kDown & KEY_START) goto End;
}
gfxFlushBuffers();
gfxSwapBuffers();
//Wait for VBlank
gspWaitForVBlank();
sleep(.075);
}
End:
// Exit services
httpcExit();
gfxExit();
return 0;
}
Last edited by JackMacWindows,




