bad request from http request of PSP, why.....

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
ldqmoon
Posts: 13
Joined: Tue Dec 04, 2007 1:17 am

bad request from http request of PSP, why.....

Post by ldqmoon »

I use the code next on PSP to get a page from internet. but it alway reture "400 bad request". I don't know why, it can work well on PC.

of cause, I had connected to the wifi.

Thanks for your suggestion.

Code: Select all

int http(void)
{
// http request
char Cmd[512]="GET /index.html http/1.1\r\n\
Host:www.acgclub.com\r\n\
Accept:*/*\r\n\
User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt; DTS Agent;)\r\n\
Connection:Keep-Alive\r\nCache-Control: no-cache\r\n\r\n";

int HTTPSocket; // http socket
struct sockaddr_in BindSocket;

char temp[512];
int bReturn;

// socket
pspprintf(" create socket\n");
HTTPSocket=socket(PF_INET, SOCK_STREAM, 0);
if&#40;HTTPSocket < 0&#41;
&#123;
pspprintf&#40;"Error when socket"&#41;;
return 0;
&#125;

//
BindSocket.sin_addr.s_addr = inet_addr &#40;"61.152.94.145"&#41;; // www.acgclub.com
BindSocket.sin_family=AF_INET;
BindSocket.sin_port=htons&#40;80&#41;;


// 
pspprintf&#40;"connect\n"&#41;;
if &#40;connect&#40;HTTPSocket, &#40;struct sockaddr *&#41;&BindSocket, sizeof&#40;BindSocket&#41;&#41;<0&#41;
&#123;
close&#40;HTTPSocket&#41;;
pspprintf&#40;"connect failed"&#41;;
return 0;
&#125;

//&#36865;http request
pspprintf&#40;"%s", Cmd&#41;;
pspprintf&#40;"\n\n"&#41;;

if&#40;send&#40;HTTPSocket, Cmd, strlen&#40;Cmd&#41;, 0&#41; <0&#41;
&#123;
close&#40;HTTPSocket&#41;;
pspprintf&#40;"send http header request failed\n"&#41;;
return 0;
&#125;

pspprintf&#40;"http header\n"&#41;;

///get http http header
bReturn=GetHttpHeader&#40;HTTPSocket,temp&#41;;
if&#40;!bReturn&#41;
&#123;
close&#40;HTTPSocket&#41;;
pspprintf&#40;"get http header failed\n"&#41;;
return 0;
&#125;
pspprintf&#40;"ok\n"&#41;;
pspprintf&#40;"%s", temp&#41;;

close&#40;HTTPSocket&#41;;
return 1;
&#125;
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

I get the same result in my computer browser for that IP...
ldqmoon
Posts: 13
Joined: Tue Dec 04, 2007 1:17 am

Post by ldqmoon »

oh... it's a Chinese IP, I don't know if it can be open in other country.

But even if I change to another URL, it also get "bad request" .
adrahil
Posts: 274
Joined: Thu Mar 16, 2006 1:55 am

Post by adrahil »

Strangely enough changing "GET /index.html http/1.1" to "GET /index.html HTTP/1.1" works for me...
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

You'd best stick to following protocols down to the last (capital) letter.
Post Reply