首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

急求解决方案:HTTP/1.1 400 Bad Request,该如何处理

2012-06-07 
急求解决方案:HTTP/1.1 400 Bad Request我写了一个http请求的程序,从网上下载一个m3u8的文件。但是不知道为

急求解决方案:HTTP/1.1 400 Bad Request
我写了一个http请求的程序,从网上下载一个m3u8的文件。但是不知道为啥总是返回HTTP/1.1 400 Bad Request,求高人指教!!!

返回数据:

HTTP/1.1 400 Bad Request
Date: Mon, 09 Aug 2010 03:27:43 GMT
Server: Apache/2.2.3 (CentOS)
Content-Length: 315
Connection: close
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<hr>
<address>Apache/2.2.3 (CentOS) Server at http://live.tvmining.com Port 80</address>
</body></html>

程序代码:
static int main(){
  SOCKET sSocket = INVALID_SOCKET;
  SOCKADDR_IN stSvrAddrIn = {0}; /* 服务器端地址 */
  char sndBuf[1024] = {0};
  char rcvBuf[1024*200] = {0};
  char *pRcv = rcvBuf;
  int num = 0;
  int nRet = SOCKET_ERROR;

  WSADATA wsaData;

  int tmplen = 348;

  FILE*fp = fopen("D:\\vs2005\\httpRequest\\debug\\http.dat", "wb");

  if( fp == NULL )
return -1;

  /* HTTP 消息构造开始,这是程序的关键之处 */
  sprintf(sndBuf, "GET /m3u8/assign/12345678_20100722_174735_ShenZhenTV_256000.m3u8 HTTP/1.1\r\n");
  strcat(sndBuf, "Host: http://live.tvmining.com\n\r\n");
  
#ifdef WIN32
{
if (WSAStartup(0x202, &wsaData) == SOCKET_ERROR)
{
perror("WSAStartup");
return -1;
}
}
#endif

  stSvrAddrIn.sin_family = AF_INET;
  stSvrAddrIn.sin_port = htons(80);
  stSvrAddrIn.sin_addr.s_addr = inet_addr("122.193.143.112");

  sSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

  /* 连接 */
  nRet = connect(sSocket, (SOCKADDR*)&stSvrAddrIn, sizeof(SOCKADDR));
  if (SOCKET_ERROR == nRet)
  {
printf("connect fail!\n");
goto GOEND;
  }
  
  /* 发送HTTP请求消息 */
  send(sSocket, (char*)sndBuf, sizeof(sndBuf), 0);

  /* 接收HTTP响应消息 */
  while(1)
  {
  num = recv(sSocket, rcvBuf, 2048, 0);

  if((0 == num) || (-1 == num))
  {
break ;
  }
  fwrite(rcvBuf, 1, num, fp);

  }


GOEND:
#ifdef WIN32
WSACleanup();
#endif

  fclose(fp);

  return 0;
}

[解决办法]
貌似你的REQUEST没构造好。。。
[解决办法]
1,host 这里去掉 http://
[解决办法]
Your browser sent a request that this server could not understand


sprintf(sndBuf, "GET /m3u8/assign/12345678_20100722_174735_ShenZhenTV_256000.m3u8 HTTP/1.1\r\n");
strcat(sndBuf, "Host: http://live.tvmining.com\r\n\r\n");

热点排行
Bad Request.