473,387 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

socket

Hi. I need to send an HTTP post specifying password and username to a
web server through a socket in order to login. I'm writing this
program in c under a linux system. How does the request has to be
formatted? I send the request using the following code:

write( socket_fd, buffer, strlen( buffer ));

where socket_fd is the socket descriptor, buffer is the string
containing the post request and strlen(buffer) its length.

thank you

Sep 23 '06 #1
5 3569
Teo81 schrieb:
Hi. I need to send an HTTP post specifying password and username to a
web server through a socket in order to login. I'm writing this
program in c under a linux system. How does the request has to be
formatted? I send the request using the following code:

write( socket_fd, buffer, strlen( buffer ));

where socket_fd is the socket descriptor, buffer is the string
containing the post request and strlen(buffer) its length.
comp.lang.c is not the right place for this question[*]; I'd try
comp.unix.programmer.
Cheers
Michael
[*] Have a look at http://clc-wiki.net 's introduction to
comp.lang.c
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Sep 23 '06 #2
Teo81 wrote:
Hi. I need to send an HTTP post specifying password and username to a
web server through a socket in order to login. I'm writing this
program in c under a linux system. How does the request has to be
formatted? I send the request using the following code:

write( socket_fd, buffer, strlen( buffer ));

where socket_fd is the socket descriptor, buffer is the string
containing the post request and strlen(buffer) its length.

thank you
As previously stated by Michael Mair this is not the correct place to
ask this question, however I am unaware of the correct newsgroup to
direct you to.

Since by chance I have previously done what you are attempting to do,
here is my two cents. If you need any additional information either find
the relevant newsgroup or try searching google for "http 1.1 rfc" (or
http 1.0 depending on your needs):

<OT>
Authorization is the http header you are needing. The format is as follows:

Authorization: cxHvb57

In the above example, Authorization is the header you need to send, : is
the delimiter used to separate the header name from the value, and
cxHvb57 is a base64 encoded string in the form "username:password". For
example (in pseudo-code) :

size_t http_base64_encode(char *username, char *password, char *tmp)
{
sprintf(tmp, "%s:%s", username, password);

/* do your encoding on tmp here */

return(strlen(tmp));
}

int main(void)
{
char temp[1024];
char stub[200];

http_base64_encode("foo", "bar", stub);

sprintf(temp, "Authorization: %s", stub);

write(socket_fd, temp, strlen(temp));
}
</OT>
Sep 24 '06 #3

Teo81 wrote:
Hi. I need to send an HTTP post specifying password and username to a
web server through a socket in order to login. I'm writing this
program in c under a linux system. How does the request has to be
formatted? I send the request using the following code:

write( socket_fd, buffer, strlen( buffer ));

where socket_fd is the socket descriptor, buffer is the string
containing the post request and strlen(buffer) its length.

thank you
Read HTTP protocol RFC.

The post data would be in the HTTP protocol data part. So you need to
send the HTTP header first then the data.

POST /login.cgi http/1.1\r\n
\r\n\r\n
username=user&password=pass

ps. each line in protocol headers ends with CRLF and protocol headers
end with two CRLF

for quick understanding
http://www.jmarshall.com/easy/http/
http://en.wikipedia.org/wiki/HTTP

-kondal

Sep 24 '06 #4
On Sat, 23 Sep 2006 20:56:21 -0500, in comp.lang.c , Joe Estock
<je*****@NOSPAMnutextonline.comwrote:
>As previously stated by Michael Mair this is not the correct place to
ask this question, however I am unaware of the correct newsgroup to
direct you to.
A unix programming one.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Sep 24 '06 #5
Mark McIntyre wrote:
On Sat, 23 Sep 2006 20:56:21 -0500, in comp.lang.c , Joe Estock
<je*****@NOSPAMnutextonline.comwrote:
>As previously stated by Michael Mair this is not the correct place to
ask this question, however I am unaware of the correct newsgroup to
direct you to.

A unix programming one.
I'm not so sure this is a unix-specific question. The OP seems to
understand the code and the logic just fine, hence my response. If
anything this was more of a protocol issue.
Sep 26 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: simon place | last post by:
Spent some very frustrating hours recoding to find a way of closing a server socket, i'd not thought it would be any problem, however, after complete failure and as a last resort, i looked at the...
4
by: DreJoh | last post by:
I've read many articles on the subject and the majority of them give the same solution that's in article 821625 on the MSDN website. I'm using the following code and when a the client disconnects...
6
by: roger beniot | last post by:
I have a program that launches multiple threads with a ThreadStart method like the following (using System.Net.Sockets.Socket for UDP packet transfers to a server): ThreadStart pseudo code: ...
4
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
9
by: Macca | last post by:
Hi, I have a synchronous socket server which my app uses to read data from clients. To test this I have a simulated client that sends 100 byte packets. I have set up the socket server so...
2
by: Macca | last post by:
My app has an asynchronous socket server. It will have 20 clients connected to the server. Each client sends data every 500 millisecondsThe Connections once established will not be closed unless...
0
by: Macca | last post by:
Hi, I am writing an asychronous socket server to handle 20+ simulataneous connections. I have used the example in MSDN as a base. The code is shown at end of question. Each connection has a...
3
by: BuddyWork | last post by:
Hello, Could someone please explain why the Socket.Send is slow to send to the same process it sending from. Eg. Process1 calls Socket.Send which sends to the same IP address and port, the...
5
by: darthghandi | last post by:
I've created a class to listen to all interfaces and do a BeginAccept(). Once it gets a connection, it passes the connected socket off and stores it in a List. Next, it continues to listen for...
4
by: O.B. | last post by:
I have a socket configured as TCP and running as a listener. When I close socket, it doesn't always free up the port immediately. Even when no connections have been made to it. So when I open...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.