[R] problem post request with RCurl

Rajarshi Guha rajarshi.guha at gmail.com
Thu Nov 19 04:26:37 CET 2009


Hi, I am trying to use a CGI service (Pubchem PUG) via RCurl and am  
running into a problem where the data must be supplied via POST - but  
I don't know the keyword for the argument.

The data to be sent is an XML fragment. I can do this via the command  
line using curl: I save the XML string to a file called query.xml and  
then do

curl -d @query.xml "http://pubchem.ncbi.nlm.nih.gov/pug/pug.cgi"

I get the expected response. More importantly, the verbose option shows:

 > Accept: */*
 > Content-Length: 1227
 > Content-Type: application/x-www-form-urlencoded

However, when I try to do this via RCurl, the data doesn't seem to get  
sent:

q <- "<PCT-Data>  <PCT-Data_input>    <PCT-InputData>      <PCT- 
InputData_query>        <PCT-Query>          <PCT- 
Query_type>            <PCT-QueryType>              <PCT- 
QueryType_qas>                <PCT- 
QueryActivitySummary>                  <PCT- 
QueryActivitySummary_output value=\"summary-table\">0</PCT- 
QueryActivitySummary_output>                  <PCT- 
QueryActivitySummary_type value=\"assay-central\">0</PCT- 
QueryActivitySummary_type>                  <PCT- 
QueryActivitySummary_scids>                    <PCT- 
QueryUids>                      <PCT- 
QueryUids_ids>                        <PCT-ID- 
List>                          <PCT-ID-List_db>pccompound</PCT-ID- 
List_db>                          <PCT-ID- 
List_uids>                            <PCT-ID-List_uids_E>3243128</PCT- 
ID-List_uids_E>                          </PCT-ID- 
List_uids>                        </PCT-ID-List>                       
</PCT-QueryUids_ids>                    </PCT- 
QueryUids>                  </PCT- 
QueryActivitySummary_scids>                </PCT- 
QueryActivitySummary>              </PCT-QueryType_qas>            </ 
PCT-QueryType>          </PCT-Query_type>        </PCT-Query>      </ 
PCT-InputData_query>    </PCT-InputData>  </PCT-Data_input></PCT-Data>"

 > postForm(url, q, style="post", .opts = list(verbose=TRUE))
* About to connect() to pubchem.ncbi.nlm.nih.gov port 80 (#0)
*   Trying 130.14.29.110... * connected
* Connected to pubchem.ncbi.nlm.nih.gov (130.14.29.110) port 80 (#0)
 > POST /pug/pug.cgi HTTP/1.1
Host: pubchem.ncbi.nlm.nih.gov
Accept: */*
Content-Length: 0
Content-Type: application/x-www-form-urlencoded

As you can see, the data in q doesn't seem to get sent (content-length  
= 0).

Does anybody have any suggestions as to why the call to postForm  
doesn't work, but the command line call does?

Thanks,

----------------------------------------------------
Rajarshi Guha        | NIH Chemical Genomics Center
http://www.rguha.net | http://ncgc.nih.gov
----------------------------------------------------
Q:  Why did the mathematician name his dog "Cauchy"?
A:  Because he left a residue at every pole.




More information about the R-help mailing list