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

error in sending post to log in google account

hi
i am trying to authenticate a user using ClientLogin by sending a
post to https://www.google.com/accounts/ClientLogin
in my c program use ssl and socket
the next code is my request:
sprintf(request, "POST /accounts/ClientLogin HTTP/1.0\r\nContent-type:
application/x-www-form-urlencoded\r\nContent-length:1357\r
\nE************@sina.com&Passwd=mypasswd&service=l h2&source=sd-aa-1.0\r
\n");

but the response is null

i do not known what's wrong, if you have some advise, email me or
response
thanks
Nov 15 '07 #1
5 2221
On Wed, 14 Nov 2007 17:57:08 -0800 (PST), lanclot
<wi*******@gmail.comwrote in comp.lang.c:
hi
i am trying to authenticate a user using ClientLogin by sending a
post to https://www.google.com/accounts/ClientLogin
in my c program use ssl and socket
SSL and socket are not part of the C language or its library. They
are extensions to the language, and off-topic here.
the next code is my request:
sprintf(request, "POST /accounts/ClientLogin HTTP/1.0\r\nContent-type:
application/x-www-form-urlencoded\r\nContent-length:1357\r
\nE************@sina.com&Passwd=mypasswd&service=l h2&source=sd-aa-1.0\r
\n");
This sprintf() call will create an exact copy of the string literal in
the array of characters pointed to by "request", assuming "request" is
a pointer to char and it points to enough non-const chars.

If "request" a pointer to enough characters? Does it contain what you
expect it to contain after the function call?
but the response is null
You haven't told us where the response comes from, so far you have
only shown us a call to sprintf() that might or might not be correct,
depending on the definition of "request" and of whatever "request"
points to.
i do not known what's wrong, if you have some advise, email me or
response
thanks
You need to post this to a group that supports your compiler/operating
system combination, and most likely you need to show more code, like
what it does after the sprintf() call.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Nov 15 '07 #2
i am sorry for my list.
i have not given enough information for my question.
my os is fedora use gcc compile
i am trying to write a application to login google picasa, now i
will give more code for it
thanks for your attention
if (connect(sockfd, (struct sockaddr *) (&server_addr),
sizeof(struct sockaddr)) == -1) { /*Á¬½ÓÍøÕ¾ */
if (DEBUG)
fprintf(stderr, "Connect Error:%s\a\n", strerror(errno));
exit(1);
}

/* SSL³õʼ»¯ */
SSL_library_init();
SSL_load_error_strings();
ctx = SSL_CTX_new(SSLv23_client_method());
if (ctx == NULL) {
ERR_print_errors_fp(stderr);
exit(1);
}

ssl = SSL_new(ctx);
if (ssl == NULL) {
ERR_print_errors_fp(stderr);
exit(1);
}

/* °ÑsocketºÍSSL¹ØÁª */
ret = SSL_set_fd(ssl, sockfd);
if (ret == 0) {
ERR_print_errors_fp(stderr);
exit(1);
}

RAND_poll();
while (RAND_status() == 0) {
unsigned short rand_ret = rand() % 65536;
RAND_seed(&rand_ret, sizeof(rand_ret));
}

ret = SSL_connect(ssl);
if (ret != 1) {
ERR_print_errors_fp(stderr);
exit(1);
}
sprintf(request, "POST /accounts/ClientLogin HTTP/1.0\r\nContent-
length:1344\r\nContent-type: application/x-www-form-urlencoded\r
\na********************************************@si na.com&Passwd=031126&service=lh2&source=sd4-
aa-1.0\r\nHost: %s:%d\r\nConnection: Close\r\n\r\n",
host_addr,portnumber);

if (DEBUG)
printf("%s", request); /* prepare request£¬ */
if (host_file && *host_file)
pt = Rstrchr(host_file, '/');
else
pt = 0;

memset(local_file, 0, sizeof(local_file));
if (pt && *pt) {
if ((pt + 1) && *(pt + 1))
strcpy(local_file, pt + 1);
else
memcpy(local_file, host_file, strlen(host_file) - 1);
} else if (host_file && *host_file)
strcpy(local_file, host_file);
else
strcpy(local_file, "index.html");
if (DEBUG)
printf("local filename to write:%s\r\n", local_file);

/send https request */
send = 0;
totalsend = 0;
nbytes = strlen(request);
while (totalsend < nbytes) {
send = SSL_write(ssl, request + totalsend, nbytes -
totalsend);
if (send == -1) {
if (DEBUG)
ERR_print_errors_fp(stderr);
exit(0);
}
totalsend += send;
if (DEBUG)
printf("%d bytes send OK!\n", totalsend);
}

fp = fopen(local_file, "a");
if (!fp) {
if (DEBUG)
printf("create file error! %s\n", strerror(errno));
return 0;
}
if (DEBUG)
printf("\nThe following is the response header:\n");
i = 0;
/* connected£¬response https */
while ((nbytes = SSL_read(ssl, buffer, 1)) == 1) {
if (i < 4) {
if (buffer[0] == '\r' || buffer[0] == '\n')
i++;
else
i = 0;
if (DEBUG)
printf("%c", buffer[0]); /*print https header
info */
} else {
fwrite(buffer, 1, 1, fp);
i++;
if (i % 1024 == 0)
fflush(fp);
}
}
fclose(fp);
Nov 15 '07 #3
lanclot wrote:
>
hi
i am trying to authenticate a user using ClientLogin by sending a
post to https://www.google.com/accounts/ClientLogin
in my c program use ssl and socket
the next code is my request:
sprintf(request, "POST /accounts/ClientLogin HTTP/1.0\r\nContent-type:
application/x-www-form-urlencoded\r\nContent-length:1357\r
\nE************@sina.com&Passwd=mypasswd&service=l h2&source=sd-aa-1.0\r
\n");

but the response is null

i do not known what's wrong, if you have some advise, email me or
response
Well, SSL, sockets, HTTP, and so on are off-topic here. However,
is it possible that the fact that you are putting both a '\r' and
a '\n' to mark EOL cause you problems?

Beyond that, you'll need to ask somewhere that can answer questions
on your SSL library.

(And if that is really a valid email address and password that you
posted in your followup, I would suggest that you change the password
ASAP.)

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Nov 15 '07 #4
On Wed, 14 Nov 2007 21:33:29 -0800 (PST), lanclot
<wi*******@gmail.comwrote in comp.lang.c:
i am sorry for my list.
i have not given enough information for my question.
my os is fedora use gcc compile
i am trying to write a application to login google picasa, now i
will give more code for it
thanks for your attention
[snip]

You missed the most important point of my reply, and of Kenneth's as
well.

There are no sockets or SSL in standard C, so we do not talk about
them here.

The libraries you are using are extensions to the language provided by
your compiler and operating system.

Now that you have specified what these are, I can tell you the correct
place to ask for help: news:comp.os.linux.development.apps

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Nov 16 '07 #5
On Wed, 14 Nov 2007 21:33:29 -0800 (PST), lanclot
<wi*******@gmail.comwrote:

<snip>
sprintf(request, "POST /accounts/ClientLogin HTTP/1.0\r\nContent-
length:1344\r\nContent-type: application/x-www-form-urlencoded\r
\na********************************************@si na.com&Passwd=031126&service=lh2&source=sd4-
aa-1.0\r\nHost: %s:%d\r\nConnection: Close\r\n\r\n",
host_addr,portnumber);
<ontopic>
You still haven't shown the declaration and if applicable allocation
of request. Unless it points to a sufficient number of writable char's
for the data sprintf puts there, you have Undefined Behavior.
<offtopic>
If it does, you have a bogus HTTP/1.0 request.

Most seriously you have data intermixed with the headers. POST data
must follow the end of header (\r\n\r\n *) and content-length's value
must give its length; your data here is nowhere near 1344 chars=bytes.
(* Technically, CR LF CR LF; like many Internet protocols HTTP is
defined in ASCII or an extension thereof, while C does not require
ASCII so \n and \r in C could actually be newline and return in some
different character set, and not the correct codes for HTTP -- but not
on systems you're likely to use.)

Also, Host: is not defined for 1.0, and if the server supports it as
an extension compatible with 1.1 putting an _address_ in it rather
than a (domain) name defeats the purpose for which it was defined.

Finally, Connection: is not standard in 1.0 and the default is already
equivalent to connection=close.
</>
if (DEBUG)
printf("%s", request); /* prepare request£¬ */

Minor point: requests with body don't need to end with an end-of-line
(\n in C), so you probably want to add one at least conditionally.
Formally C allows an implementation to not support/allow text files
where the last line doesn't end with a newline; in practice most do,
almost certainly including yours, but it's still confusing and ugly.
if (host_file && *host_file)
pt = Rstrchr(host_file, '/');
else
pt = 0;
If (nonstandard) Rstrchr doesn't do something very much like the
standard strchr, it is confusingly named. If it does ...
memset(local_file, 0, sizeof(local_file));
if (pt && *pt) {
.... this test is redundant; if pt was set to point to a character in a
string then both pt != NULL and *pt != '\0'; if it was set to 0 then
pt == NULL (and *pt must not be and is not tested).
if ((pt + 1) && *(pt + 1))
.... and so is this. If pt points to a character in a string and is
necessarily nonnull, then pt+1 is also nonnull. Checking *(pt+1) is
useful, although pt[1] is equivalent and arguably more idiomatic.
strcpy(local_file, pt + 1);
else
memcpy(local_file, host_file, strlen(host_file) - 1);
You really want to use all but the last character of (the contents of
or value pointed to by) host_file? That seems odd.

<snip>
i = 0;
/* connected£¬response https */
while ((nbytes = SSL_read(ssl, buffer, 1)) == 1) {
<semi-offtopicCalling SSL_read for each character will probably
waste quite a bit of CPU, at least assuming this is openssl as it
appears. (Openssl in particular is offtopic, but IMO the general
concept of few large calls versus many small ones is ontopic.) </>
if (i < 4) {
if (buffer[0] == '\r' || buffer[0] == '\n')
i++;
else
i = 0;
if (DEBUG)
printf("%c", buffer[0]); /*print https header
info */
} else {
fwrite(buffer, 1, 1, fp);
i++;
if (i % 1024 == 0)
fflush(fp);
}
}
This doesn't make sense. It appears you are trying to use the same
variable, i, both to count data received/written and count consecutive
\r and \n to find end-of-header. Those are conflicting uses.

Also, flushing output every 1024 bytes is dubious. 1024 doesn't have
any particular significance to the HTTP format, except by the remotest
chance; and while it might matter to the buffering done by stdio,
stdio will already flush whenever it needs to based on its (actual)
buffering without you even thinking about it -- that's one of the
reasons for having and using stdio in the first place.
fclose(fp);
- formerly david.thompson1 || achar(64) || worldnet.att.net
Nov 25 '07 #6

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

Similar topics

0
by: David Moore | last post by:
Hello I posted a thread about this a while back, but I can't actually find it again so I can reply to it with the solution I found, so I'm making a new thread and hoping it goes to the top of...
3
by: delraydog | last post by:
I'm having a problem on Windows 2003 Server with this script. It appears to be a problem with MS XML 4.0 as this code was working fine under MS XML 3.0 and Windows XP or 2000. Any ideas? The...
8
by: Rod | last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some reason, opening some ASP.NET applications we wrote is producing the following error message: "The Web server reported...
5
by: Kevin Swanson | last post by:
First, apologies for cross-posting. I posted this message originally in exchange2000.development, but it looks like that's an unmanaged group. At least it doesn't show up in the list when looking...
13
by: yawnmoth | last post by:
Say I wrote an ajax script to send out HTTP requests via ajax. Any cookies that I have associated with that site will be sent along with this HTTP request. Is there a way to prevent this from...
10
by: JLuis Estrada | last post by:
Hi there Its my 1st post in this group and I hope we could have a great time. well, this is my problem I was debbuging my app (a website) and the system get stuck and I had to reboot the...
23
by: deathtospam | last post by:
A day or two ago, I wrote a quick ASPX page with a CS codebehind using Visual Studio .NET 2005 -- it worked, I saved it and closed the project. Today, I came back to the project, reopened the...
6
by: =?Utf-8?B?RGF2ZQ==?= | last post by:
I'm running VS 2003/ASP.NET 1.1.4322.0 on XP SP2 All of a sudden I started to getting... "Error while trying to run project: Unable to start debugging on the web server. Server side-error...
6
by: Dave Kelly | last post by:
Sorry for the long post, it is easier to discard information than to have to wait for it to arrive. So here goes: This code worked perfectly when I was an Earthlink customer. Sprint decided...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.