Equivalent of Java HTTPClient in PHP
Posted: Thu Jul 09, 2009 9:53 am
I want to recreate the following method using PHP but I'm not sure what the equivalent PHP Method is for the Java HTTPClient. Is it HTTPRequest? ofxRequest.toString() would return a string like the following:
That then gets added to a StringRequestEntity which i don't fully understand the purpose of. If HTTPRequest is the PHP method I want to use then what is the equivalent use of StringRequestEntity.
Code: Select all
"OFXHEADER:100\n
DATA:OFXSGML\n
VERSION:102\n
SECURITY:NONE\n
ENCODING:USASCII\n
CHARSET:1252\n
COMPRESSION:NONE\n
OLDFILEUID:oldFileID\n
NEWFILEUID:newFileID\n"
Code: Select all
public OFXResponse getOFXResponse(OFXRequest ofxRequest) throws OFXSignOnException {
System.out.println("*****Sending request*****");
System.out.println(ofxRequest.toString());
PostMethod method = new PostMethod(NW_URL);
RequestEntity request;
String response = null;
try {
request = new StringRequestEntity(ofxRequest.toString(), "application/x-ofx", "UTF-8");
method.setRequestEntity(request);
client.executeMethod(method);
response = method.getResponseBodyAsString();
System.out.println( "Response: " + response); }
catch (UnsupportedEncodingException e) {
//Should never happen
e.printStackTrace(); }
catch (HttpException e) {
e.printStackTrace(); }
catch (IOException e) { .
e.printStackTrace(); } //clean up the connection resources
method.releaseConnection(); //Something must have gone wrong
if (response == null) return null;
OFXResponse ofxResponse = new OFXResponse(response);
//Check for any status errors and throw exceptions if anything is not right
handleResponseStatus(ofxResponse);
return ofxResponse;
}