I'm trying to post to Blogger using idHTTP component, however, I'm getting "HTTP/1.0 400 Bad Request" error.
First, I get the Auth code, which works perfectly with by using code below:
TStringList *request = new TStringList;
TStringList *response = new TStringList();
IdHTTP2->Request->Connection = "Keep-Alive";
IdHTTP2->Request->ContentType = "application/x-www-form-urlencoded";
IdSSLIOHandlerSocketOpenSSL1->SSLOptions->Method = sslvSSLv23;
request->Clear();
request->Values["accountType"] = "GOOGLE";
request->Values["Email"] = "[email protected]";
request->Values["Passwd"] = "yyyyyyy";
request->Values["source"] = "test-test";
request->Values["service"] = "blogger";
response->Text = IdHTTP2->Post("https://www.google.com/accounts/ClientLogin", request);
auth = response->Values["Auth"]; //working perfectly
Then, I get the blogID and finally I try to post an entry to Blogger using code below, but at this moment I get "HTTP/1.0 400 Bad Request" error.
request->Clear();
request->Text = Memo3->Lines->Text; //put entry into request var
IdHTTP2->Request->CustomHeaders->Clear();
IdHTTP2->Request->CustomHeaders->Add("GData-Version=2.0");
IdHTTP2->Request->CustomHeaders->Add("Authorization: GoogleLogin auth="+auth);
IdHTTP2->Request->ContentType = "application/atom+xml";
response->Text = IdHTTP2->Post("https://www.blogger.com/feeds/" + blogID + "/posts/default", request); // I got "HTTP/1.0 400 Bad Request" error right here.
This is the entry I'm trying to post:
<entry xmlns='http://www.w3.org/2005/Atom'>
<title type='text'>Marriage!</title>
<content type='xhtml'>
<div xmlns="http://www.w3.org/1999/xhtml">
<p>Mr. Darcy has <em>proposed marriage</em> to me!</p>
<p>He is the last man on earth I would ever desire to marry.</p>
<p>Whatever shall I do?</p>
</div>
</content>
<category scheme="http://www.blogger.com/atom/ns#" term="marriage" />
<category scheme="http://www.blogger.com/atom/ns#" term="Mr. Darcy" />
</entry>
I have looked for a right way of posting it with idHTTP but I found nothing.. :(
Does anyone know what I'm doing wrong?
BTW, I'm using CodeGear Delphi/C++Builder 2009 and Indy's version is 10.
Any help is greatly appreciated. Thank you!
I found out how to get it working.
I removed line
IdHTTP2->Request->CustomHeaders->Add("GData-Version=2.0");
Then I replaced
IdHTTP2->Request->CustomHeaders->Add("Authorization: GoogleLogin auth="+auth);
by
IdHTTP2->Request->CustomHeaders->Values["Authorization"] = "GoogleLogin auth="+auth;
From: https://forums.embarcadero.com/message.jspa?messageID=252770