Sending HTTP Packets (Help)

Discuss how to write good code, break bad code, your current pet projects, or the best way to approach novel problems

Sending HTTP Packets (Help)

Post by barneystinson19 on Wed Feb 06, 2013 4:10 pm
([msg=73517]see Sending HTTP Packets (Help)[/msg])

Hi,
What I want to do is to sending http packets to a host then get the response from server.
In php I can do it with two functions named fsockopen() and fputs() :

Code: Select all
/* HTTP PACKET */
$packet .= "GET /path/file.html HTTP/1.0\r\n";
$packet .= "From: something@something.com\r\n";
$packet .= "User-Agent: HTTPTool/1.0\r\n";
/* Sending packet to host */
$connection = fsockopen($host,$port);
fputs($connection, $packet);
/* Getting response */
$response = fgets($connection);
echo $response;


How can I do exactly something like this in vb.net?
"Ömür dediğin üç gündür, dün geldi geçti yarın meçhuldür…O halde ömür dediğin bir gündür,o da bugündür…."
User avatar
barneystinson19
Experienced User
Experienced User
 
Posts: 50
Joined: Fri Nov 02, 2012 3:49 pm
Blog: View Blog (0)


Re: Sending HTTP Packets (Help)

Post by centip3de on Wed Feb 06, 2013 4:35 pm
([msg=73518]see Re: Sending HTTP Packets (Help)[/msg])

barneystinson19 wrote:Hi,
What I want to do is to sending http packets to a host then get the response from server.
In php I can do it with two functions named fsockopen() and fputs() :

Code: Select all
/* HTTP PACKET */
$packet .= "GET /path/file.html HTTP/1.0\r\n";
$packet .= "From: something@something.com\r\n";
$packet .= "User-Agent: HTTPTool/1.0\r\n";
/* Sending packet to host */
$connection = fsockopen($host,$port);
fputs($connection, $packet);
/* Getting response */
$response = fgets($connection);
echo $response;


How can I do exactly something like this in vb.net?


I can't speak about VB.NET personally (and neither can the majority of those on these forums), but I can speak for the general concept behind it. The difference between VB.NET and PHP is that PHP is executed on a server. Thus, you don't need to write a server in order to send data via a network, you just need to write your basic PHP code. However, in the majority of programming languages you would need to write a server, then write a client, then connect the client to the server, then send data through the server to the client (or visa versa). This sounds much more complicated than it generally is, and can be accomplished with probably around 100-200 lines of Python (Once again, can't speak for VB.NET).
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rick Cook
User avatar
centip3de
Moderator
Moderator
 
Posts: 1430
Joined: Fri Aug 20, 2010 5:46 pm
Blog: View Blog (0)


Re: Sending HTTP Packets (Help)

Post by barneystinson19 on Wed Feb 06, 2013 4:45 pm
([msg=73520]see Re: Sending HTTP Packets (Help)[/msg])

centip3de wrote:
barneystinson19 wrote:Hi,
What I want to do is to sending http packets to a host then get the response from server.
In php I can do it with two functions named fsockopen() and fputs() :

Code: Select all
/* HTTP PACKET */
$packet .= "GET /path/file.html HTTP/1.0\r\n";
$packet .= "From: something@something.com\r\n";
$packet .= "User-Agent: HTTPTool/1.0\r\n";
/* Sending packet to host */
$connection = fsockopen($host,$port);
fputs($connection, $packet);
/* Getting response */
$response = fgets($connection);
echo $response;


How can I do exactly something like this in vb.net?


I can't speak about VB.NET personally (and neither can the majority of those on these forums), but I can speak for the general concept behind it. The difference between VB.NET and PHP is that PHP is executed on a server. Thus, you don't need to write a server in order to send data via a network, you just need to write your basic PHP code. However, in the majority of programming languages you would need to write a server, then write a client, then connect the client to the server, then send data through the server to the client (or visa versa). This sounds much more complicated than it generally is, and can be accomplished with probably around 100-200 lines of Python (Once again, can't speak for VB.NET).


First of all thanks for answering that quick :) Isn't it possible to send a http packet to an apache server without creating a client?
"Ömür dediğin üç gündür, dün geldi geçti yarın meçhuldür…O halde ömür dediğin bir gündür,o da bugündür…."
User avatar
barneystinson19
Experienced User
Experienced User
 
Posts: 50
Joined: Fri Nov 02, 2012 3:49 pm
Blog: View Blog (0)


Re: Sending HTTP Packets (Help)

Post by centip3de on Wed Feb 06, 2013 4:49 pm
([msg=73521]see Re: Sending HTTP Packets (Help)[/msg])

barneystinson19 wrote:First of all thanks for answering that quick :) Isn't it possible to send a http packet to an apache server without creating a client?


VB.NET might have something specific for this, but as far as I know, no.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rick Cook
User avatar
centip3de
Moderator
Moderator
 
Posts: 1430
Joined: Fri Aug 20, 2010 5:46 pm
Blog: View Blog (0)


Re: Sending HTTP Packets (Help)

Post by barneystinson19 on Wed Feb 06, 2013 5:04 pm
([msg=73522]see Re: Sending HTTP Packets (Help)[/msg])

centip3de wrote:
barneystinson19 wrote:First of all thanks for answering that quick :) Isn't it possible to send a http packet to an apache server without creating a client?


VB.NET might have something specific for this, but as far as I know, no.


I think I might found something;
http://msdn.microsoft.com/en-us/library ... snippet-27
I'll try it thanks for answers :)
"Ömür dediğin üç gündür, dün geldi geçti yarın meçhuldür…O halde ömür dediğin bir gündür,o da bugündür…."
User avatar
barneystinson19
Experienced User
Experienced User
 
Posts: 50
Joined: Fri Nov 02, 2012 3:49 pm
Blog: View Blog (0)


Re: Sending HTTP Packets (Help)

Post by WallShadow on Wed Feb 06, 2013 5:40 pm
([msg=73525]see Re: Sending HTTP Packets (Help)[/msg])

barneystinson19 wrote:Hi,
Code: Select all
/* HTTP PACKET */
$packet .= "GET /path/file.html HTTP/1.0\r\n";
$packet .= "From: something@something.com\r\n";
$packet .= "User-Agent: HTTPTool/1.0\r\n";
/* Sending packet to host */
$connection = fsockopen($host,$port);
fputs($connection, $packet);
/* Getting response */
$response = fgets($connection);
echo $response;



There is no such thing as an HTTP packet, HTTP works on a different level of the OSI model. That, what you are doing is sending an HTTP request. Unbeknownst to you, you are sending multiple TCP/IP packets which effectively transmit your HTTP request. Please remember that for the future <3
User avatar
WallShadow
Contributor
Contributor
 
Posts: 594
Joined: Tue Mar 06, 2012 9:37 pm
Blog: View Blog (0)


Re: Sending HTTP Packets (Help)

Post by barneystinson19 on Wed Feb 06, 2013 6:19 pm
([msg=73529]see Re: Sending HTTP Packets (Help)[/msg])

WallShadow wrote:
barneystinson19 wrote:Hi,
Code: Select all
/* HTTP PACKET */
$packet .= "GET /path/file.html HTTP/1.0\r\n";
$packet .= "From: something@something.com\r\n";
$packet .= "User-Agent: HTTPTool/1.0\r\n";
/* Sending packet to host */
$connection = fsockopen($host,$port);
fputs($connection, $packet);
/* Getting response */
$response = fgets($connection);
echo $response;



There is no such thing as an HTTP packet, HTTP works on a different level of the OSI model. That, what you are doing is sending an HTTP request. Unbeknownst to you, you are sending multiple TCP/IP packets which effectively transmit your HTTP request. Please remember that for the future <3


That was what I meant sorry about my bad english ^^

-- Wed Feb 06, 2013 6:24 pm --

How can I upload files with post request in vb.net?
"Ömür dediğin üç gündür, dün geldi geçti yarın meçhuldür…O halde ömür dediğin bir gündür,o da bugündür…."
User avatar
barneystinson19
Experienced User
Experienced User
 
Posts: 50
Joined: Fri Nov 02, 2012 3:49 pm
Blog: View Blog (0)


Re: Sending HTTP Packets (Help)

Post by fashizzlepop on Wed Feb 06, 2013 8:38 pm
([msg=73530]see Re: Sending HTTP Packets (Help)[/msg])

centip3de wrote:I can't speak about VB.NET personally (and neither can the majority of those on these forums), but I can speak for the general concept behind it. The difference between VB.NET and PHP is that PHP is executed on a server. Thus, you don't need to write a server in order to send data via a network, you just need to write your basic PHP code. However, in the majority of programming languages you would need to write a server, then write a client, then connect the client to the server, then send data through the server to the client (or visa versa). This sounds much more complicated than it generally is, and can be accomplished with probably around 100-200 lines of Python (Once again, can't speak for VB.NET).

Sorry, cent, but you're wrong. To just send and receive HTTP requests you only have to open a socket and send the data appropriately. No server needed on your end.

I have no idea how to go about this in VB.net. With that said, if you can figure out how to do ANY HTTP requests, you should be able to do a post or get by just constructing your header and request properly.

Here's the RFC but it's kinda bulky.

This might be easier to understand.

Otherwise Google HTTP Requests (optionally add in VB.net to your search).
The glass is neither half-full nor half-empty; it's merely twice as big as it needs to be.
User avatar
fashizzlepop
Developer
Developer
 
Posts: 2303
Joined: Sat May 24, 2008 1:20 pm
Blog: View Blog (0)


Re: Sending HTTP Packets (Help)

Post by barneystinson19 on Wed Feb 06, 2013 8:58 pm
([msg=73532]see Re: Sending HTTP Packets (Help)[/msg])

fashizzlepop wrote:
centip3de wrote:I can't speak about VB.NET personally (and neither can the majority of those on these forums), but I can speak for the general concept behind it. The difference between VB.NET and PHP is that PHP is executed on a server. Thus, you don't need to write a server in order to send data via a network, you just need to write your basic PHP code. However, in the majority of programming languages you would need to write a server, then write a client, then connect the client to the server, then send data through the server to the client (or visa versa). This sounds much more complicated than it generally is, and can be accomplished with probably around 100-200 lines of Python (Once again, can't speak for VB.NET).

Sorry, cent, but you're wrong. To just send and receive HTTP requests you only have to open a socket and send the data appropriately. No server needed on your end.

I have no idea how to go about this in VB.net. With that said, if you can figure out how to do ANY HTTP requests, you should be able to do a post or get by just constructing your header and request properly.

Here's the RFC but it's kinda bulky.

This might be easier to understand.

Otherwise Google HTTP Requests (optionally add in VB.net to your search).


Thanks that helped alot about HTTP Requests :) But I still don't know how to send packets in vb.net like the php example. I found something about webrequest in vb.net but its not the exact way I want :/ Anyway thanks for your answers I'll keep searching :)
"Ömür dediğin üç gündür, dün geldi geçti yarın meçhuldür…O halde ömür dediğin bir gündür,o da bugündür…."
User avatar
barneystinson19
Experienced User
Experienced User
 
Posts: 50
Joined: Fri Nov 02, 2012 3:49 pm
Blog: View Blog (0)


Re: Sending HTTP Packets (Help)

Post by centip3de on Thu Feb 07, 2013 2:43 pm
([msg=73547]see Re: Sending HTTP Packets (Help)[/msg])

fashizzlepop wrote:Sorry, cent, but you're wrong. To just send and receive HTTP requests you only have to open a socket and send the data appropriately. No server needed on your end.

I have no idea how to go about this in VB.net. With that said, if you can figure out how to do ANY HTTP requests, you should be able to do a post or get by just constructing your header and request properly.

Here's the RFC but it's kinda bulky.

This might be easier to understand.

Otherwise Google HTTP Requests (optionally add in VB.net to your search).


I suppose it's all about how you define a server; in my mind, a server is something that takes and handles incoming requests, and unless you plan on sending data to nothing, you're going to need some version of a server. Granted you can send them to already set up servers, but you would still need a server.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rick Cook
User avatar
centip3de
Moderator
Moderator
 
Posts: 1430
Joined: Fri Aug 20, 2010 5:46 pm
Blog: View Blog (0)


Next

Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests