OK,

Apologies all, for using this list as my own personal "intro to java  
web programming" course..  Just to finish this off, the following  
code frag does what I was trying to do

String encodedData = "uri="+URLEncoder.encode(uri,"UTF-8") 
+"&tags="+URLEncoder.encode(tags,"UTF-8");              
URL connoU = new URL("http://www.connotea.org/data/add";);                       
HttpURLConnection conno = (HttpURLConnection) connoU.openConnection();  
conno.setDoOutput(true);
OutputStream os = conno.getOutputStream();
os.write( encodedData.getBytes() );
int code = conno.getResponseCode();
System.out.println("response code from connotea="+code);

If anyone else is having trouble reading and writing to the api from  
java, please do let me know - think I've made it through most of the  
cases.  The only one I haven't finished yet is the job of writing to  
the connotea wiki from code.  Seems that it is possible to do that  
via browser emulation (cookies etc.) but it would be cool if it was  
added to the API.

cheers all
-Ben



On Aug 2, 2007, at 5:45 PM, Martin Flack wrote:

> I don't know Java libraries, but it seems unlikely that you should  
> be using setRequestProperty() for both User-Agent (an HTTP header)  
> and uri (a form parameter).
>
> POST's are supposed to put their parameters in the payload (like  
> your web browser does) by spec.
>
> Take a look at how they encode and attach the form payload on these  
> examples:
> http://www.javaworld.com/javaworld/javatips/jw-javatip34.html
> http://developers.sun.com/mobility/midp/ttips/HTTPPost/
>
> Cheers,
> Martin
>
> Benjamin Good wrote:
>> Usually adding the parameters into the URL works .. why would it  
>> not in this case?
>> I get the same error (400) if I set the params in the code
>> URL connoU = new URL("http://www.connotea.org/data/add";);
>> HttpURLConnection conno = (HttpURLConnection) connoU.openConnection 
>> ();
>> conno.setRequestProperty("User-Agent", "WWW::Connotea");
>> conno.setRequestProperty("uri", URLEncoder.encode(uri,"UTF-8"));
>> conno.setRequestProperty("tag", URLEncoder.encode(tag,"UTF-8"));
>> conno.setRequestMethod("POST");
>> I've been digging for some else that has this running in Java, but  
>> the only one I could find (from Pierre Lindenbaum) didn't use the  
>> web api - it emulated a user session by storing and sending  
>> cookies for authentication and sending requests including button  
>> clicks.  (His ConnoteaClient program - but it doesn't seem to be  
>> work ing anymore).
>> -Ben
>

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Connotea-code-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/connotea-code-devel

Reply via email to