Advertisement
Guest User

Untitled

a guest
Feb 10th, 2017
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.59 KB | None | 0 0
  1. #define VITASDK
  2.  
  3. #include <psp2/sysmodule.h>
  4. #include <psp2/kernel/processmgr.h>
  5. #include <psp2/display.h>
  6.  
  7. #include <psp2/net/net.h>
  8. #include <psp2/net/netctl.h>
  9. #include <psp2/net/http.h>
  10.  
  11. #include <psp2/io/fcntl.h>
  12.  
  13. #include <stdio.h>
  14. #include <malloc.h>
  15. #include <string.h>
  16.  
  17. #include "debugScreen.h"
  18.  
  19. void netInit() {
  20.     psvDebugScreenPrintf("Loading module SCE_SYSMODULE_NET\n");
  21.     sceSysmoduleLoadModule(SCE_SYSMODULE_NET);
  22.    
  23.     psvDebugScreenPrintf("Running sceNetInit\n");
  24.     SceNetInitParam netInitParam;
  25.     int size = 1*1024*1024;
  26.     netInitParam.memory = malloc(size);
  27.     netInitParam.size = size;
  28.     netInitParam.flags = 0;
  29.     sceNetInit(&netInitParam);
  30.  
  31.     psvDebugScreenPrintf("Running sceNetCtlInit\n");
  32.     sceNetCtlInit();
  33. }
  34.  
  35. void netTerm() {
  36.     psvDebugScreenPrintf("Running sceNetCtlTerm\n");
  37.     sceNetCtlTerm();
  38.  
  39.     psvDebugScreenPrintf("Running sceNetTerm\n");
  40.     sceNetTerm();
  41.  
  42.     psvDebugScreenPrintf("Unloading module SCE_SYSMODULE_NET\n");
  43.     sceSysmoduleUnloadModule(SCE_SYSMODULE_NET);
  44. }
  45.  
  46. void httpInit() {
  47.     psvDebugScreenPrintf("Loading module SCE_SYSMODULE_HTTP\n");
  48.     sceSysmoduleLoadModule(SCE_SYSMODULE_HTTP);
  49.  
  50.     psvDebugScreenPrintf("Running sceHttpInit\n");
  51.     sceHttpInit(1*1024*1024);
  52. }
  53.  
  54. void httpTerm() {
  55.     psvDebugScreenPrintf("Running sceHttpTerm\n");
  56.     sceHttpTerm();
  57.  
  58.     psvDebugScreenPrintf("Unloading module SCE_SYSMODULE_HTTP\n");
  59.     sceSysmoduleUnloadModule(SCE_SYSMODULE_HTTP);
  60. }
  61.  
  62.  
  63. int main(int argc, char *argv[]) {
  64.     psvDebugScreenInit();
  65.     psvDebugScreenPrintf("(HTTP Sample v.1.0 by barooney) modified\n\n");
  66.  
  67.     netInit();
  68.     httpInit();
  69.  
  70.     /*
  71.         RELEVANT
  72.     */
  73.  
  74.     char* url = "http://192.168.1.234/test.php";
  75.     char* dest = "ux0:data/VSDK00009/index.html";
  76.     char* postData="test=happyman";
  77.     // Create template with user agend "PS Vita Sample App"
  78.     int tpl = sceHttpCreateTemplate("PS Vita Sample App", 1, 1);
  79.     // set url on the template
  80.     int conn = sceHttpCreateConnectionWithURL(tpl, url, 0);
  81.     // create the request with the correct method
  82.     int request = sceHttpCreateRequestWithURL(conn, SCE_HTTP_METHOD_POST, url, strlen(postData));
  83.     // send the actual request. Second parameter would be POST data, third would be length of it.
  84.     int handle = sceHttpSendRequest(request, postData, strlen(postData));
  85.  
  86.     /*
  87.         Less RELEVANT?
  88.     */
  89.  
  90.     int fh = sceIoOpen(dest, SCE_O_WRONLY | SCE_O_CREAT, 0777);
  91.     unsigned char data[16*1024];
  92.     int read = 0;
  93.  
  94.     while ((read = sceHttpReadData(request, &data, sizeof(data))) > 0) {
  95.         int write = sceIoWrite(fh, data, read);
  96.     }
  97.  
  98.     // close file
  99.     sceIoClose(fh);
  100.     httpTerm();
  101.     netTerm();
  102.  
  103.     sceKernelExitProcess(0);
  104.     return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement