473,386 Members | 1,733 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,386 software developers and data experts.

Http Post in C

For a C http_post example ref:

http://souptonuts.sourceforge.net/code/http_post.c.html

Regards,

Mike
Nov 13 '05 #1
3 28231
mc******@brainsquash.org (Mike Chirico) wrote in message news:<ad**************************@posting.google. com>...
For a C http_post example ref:

http://souptonuts.sourceforge.net/code/http_post.c.html

Regards,

Mike


#include <arpa/inet.h>
#include <assert.h>
#include <errno.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <unistd.h>

#define SA struct sockaddr
#define MAXLINE 4096

/* Following could be derived from SOMAXCONN in <sys/socket.h>, but many
kernels still #define it as 5, while actually supporting many more */
#define LISTENQ 1024 /* 2nd argument to listen() */

void process_http(FILE *fp, int sockfd){
char sendline[MAXLINE], recvline[MAXLINE];
ssize_t n;

strcpy(sendline,"POST /test.php HTTP/1.0\r\n");
strcat(sendline,"Host: souptonuts.sourceforge.net\r\n");
strcat(sendline,"Content-type: application/x-www-form-urlencoded\r\n");
strcat(sendline,"Content-length: 34\r\n\r\n");
strcat(sendline,"mode=login&user=test&password=tes t\r\n");
write(sockfd, sendline, strlen(sendline));
while ( ( n = read(sockfd, recvline, MAXLINE)) != 0 )
{
recvline[n]='\0';
fprintf(stderr,"%s",recvline);
}

/* Interesting note: if you want to see how many
reads there are through the while loop do a

# tcpdump src port 80

And the size of n will be the mss, value in ( ) from this
call

*/
}

int
main(int argc, char **argv)
{
int sockfd;
struct sockaddr_in servaddr;

sockfd = socket(AF_INET, SOCK_STREAM, 0);
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(80);
inet_pton(AF_INET, "66.35.250.209", &servaddr.sin_addr);

connect(sockfd, (SA *) &servaddr, sizeof(servaddr));
process_http(stdin, sockfd);
exit(0);

}
Mike Chirico
Nov 13 '05 #2
Mike Chirico wrote:
mc******@brainsquash.org (Mike Chirico) wrote in message news:<ad**************************@posting.google. com>...
For a C http_post example ref:

http://souptonuts.sourceforge.net/code/http_post.c.html

Regards,

Mike

#include <arpa/inet.h>
#include <assert.h>
#include <errno.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <unistd.h>


<snip>

This group is for discussion of the C language as defined by the
international C standard. Please don't post non-standard code here. Only
5 of those headers are standard.

This is also not a source code repository, so don't post code just to be
posting code. Only do it if you have a question or comment (relating to
the C language) about the code.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Nov 13 '05 #3
mc******@brainsquash.org (Mike Chirico) wrote:
mc******@brainsquash.org (Mike Chirico) wrote:
For a C http_post example ref:

http://souptonuts.sourceforge.net/code/http_post.c.html

#include <arpa/inet.h>

<snip>
Stop right here! What made you think that C code littered with
non-standard extensions to the language could ever be topical in
comp.lang.c?

Please read the c.l.c welcome-message

http://www.angelfire.com/ms3/bchambl...me_to_clc.html

and the c.l.c-faq

http://www.eskimo.com/~scs/C-faq/top.html

before posting here. Thank you very much.

BTW, what was your question?

Regards
--
Irrwahn
(ir*******@freenet.de)
Nov 13 '05 #4

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

Similar topics

4
by: Gary Petersen | last post by:
For the benefit of others, I want to show how to do an HTTP POST request using fsockopen(). I banged my head against a wall for two days trying to figure this out. I even went to http://php.net/...
3
by: Geoff | last post by:
I have been asked to add postal rates to a web page shopping cart checkout procedure. After contacting the post office I discovered that they used XML to receive postal rate requests and send back...
0
by: WIWA | last post by:
Hi, I want to login to a password protected website and fetch the content of the page behind. I have based my code on http://weblogs.asp.net/jdennany/archive/2005/04/23/403971.aspx. When I use...
3
by: Patrick Fogarty | last post by:
I am programming what is to be a web service client that will use an HTTP-POST to request and retrieve data. The remote server (written in java for what it's worth) requires basic authentication...
3
by: JansenH | last post by:
We have implemented a 'HTTP Post' client in C# that posts Xml documents to a webserver. This is working fine if the post rate is one post for every 20 seconds. But if the post rate is increased to...
1
by: Arfeen | last post by:
Hi All, I need help again ..... I have an asp.net web page which I hit using the "HTTP POST" method. My ASP.NET page is a basic hello world example with the following code: private void...
2
by: =?Utf-8?B?cGhlbmdsYWk=?= | last post by:
I am not sure really how to explain this but here goes. I am creating some new web services and I want to be able to post data like the following: <Data> <some value>1</some value> <more...
6
by: Brybot | last post by:
I am trying to allow HTTP POST file uploads to my web service. Currently I have it working perfectly for a SOAP/XML request reading in a byte using MemoryStream/FileStream but I cannot figure out...
2
by: MDANH2002 | last post by:
Hi From VB.NET I want to simulate the POST request of the following HTML form <html> <title>HTTP Post Testing</title> <body> <form action=http://www.example.com/postdata ...
5
by: manheim | last post by:
I have a page posting a raw jpg to me via HTTP POST. All reference I've found is centered around retrieving POST data as name/value pairs which will not work in this situation. What I need to do...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.