![]() |
| | #1 |
| Registered User Join Date: Mar 2006
Posts: 41
| Help! Http My program connects to the IP, recv()'s the data, and prints it to a file. The only thing that isn't working is that something is going wrong with TAB, CR, and LF. When I compare the actual file, with the file my program downloaded there are extra tabs and carriage returns, and the JPG doesn't work. Does anyone know what could have gone wrong? Thanks. |
| ytaipsw is offline | |
| | #2 |
| Registered User Join Date: Apr 2008
Posts: 309
| Well in an actual JPG, there shouldn't be TAB, CR, or LF, or at least in that representation. The same bytes most likely are. You will need to parse out the http header. How are you doing this? Some code could be helpful. |
| carrotcake1029 is offline | |
| | #3 |
| Registered User Join Date: Apr 2007 Location: Sydney, Australia
Posts: 217
| Extra bytes at the top of the file? If that's the case then that is part of the header. It's probably a blank line which means end of header. |
| 39ster is offline | |
| | #4 |
| Registered User Join Date: Mar 2006
Posts: 41
| the begennings and ends match its just those three characters heres my source: Code: #include <winsock.h>
#include <windows.h>
#include <stdio.h>
#include <fstream>
using namespace std;
SOCKET s;WSADATA w;
bool Connect(char* IPAddress);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) {
ofstream i;i.open("C:\\sweet.jpg");
MSG messages;bool isgo=false;char buffer[100000];int err;
isgo=Connect("64.13.232.195");
if(isgo) {
send(s,"GET /media/portraits/Hot_Bikini_Brunette.jpg HTTP/2.0\r\nHost: sirimo.co.uk\r\n\r\n",78,0);
err=recv(s,buffer,sizeof(buffer),0);
err=recv(s,buffer,sizeof(buffer),0);
for(int j=0;j<err;j+=1) {
if(buffer[j]=='\r') {i << "\n";j+=1;}
else {i << buffer[j];}}
//i << "\n" << "2: "<< err << "\n";
err=recv(s,buffer,sizeof(buffer),0);
if(s) {closesocket(s);}
WSACleanup();}
i.close();
return 0;}
bool Connect(char* IPAddress) {
WSADATA wsadata;
int error=WSAStartup(0x0202,&wsadata);
if(error) {return false;}
if(wsadata.wVersion!=0x0202) {WSACleanup();return false;}
SOCKADDR_IN target;
target.sin_family=AF_INET;
target.sin_port=htons(80);
target.sin_addr.s_addr=inet_addr(IPAddress);
s=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(s==INVALID_SOCKET) {return false;}
if(connect(s,(SOCKADDR *)&target,sizeof(target))==SOCKET_ERROR) {return false;}
else {return true;}
}
|
| ytaipsw is offline | |
| | #5 |
| CSharpener Join Date: Oct 2006
Posts: 5,321
| jpeg is binary file - should not it be opened as binary?
__________________ If I have eight hours for cutting wood, I spend six sharpening my axe. |
| vart is offline | |
| | #6 |
| Registered User Join Date: Mar 2006
Posts: 41
| yes it should be binary, that fixed it thank you |
| ytaipsw is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Error stop Http Listener | George2 | C# Programming | 1 | 06-04-2008 02:14 AM |
| my HTTP request handler code correct? | George2 | C# Programming | 0 | 04-25-2008 04:01 AM |
| C# HTTP request/response | George2 | C# Programming | 0 | 04-02-2008 06:00 AM |
| Writing all HTTP requests from a website to a log file | goomyman | C# Programming | 1 | 07-29-2005 09:18 AM |