我有一个恼人的ASP.NET问题:http POST与asp.net
我有一个Perl脚本(见下文),它获取form_info变量。 现在不幸的是,它是http POST,而不是http GET,因此Request.Querystring不起作用...
现在我必须用一个asp.net页面/ app替换Perl脚本,但是我的问题是当我没有字符串时,我无法处理字符串form_info ... 我无法将http POST更改为HTTP get,因为它是由第三方java applet生成的。
# Print out a content-type for HTTP/1.0 compatibility
print "Content-type: text/html\n\n";
#
#test whether it's via a firewall (i.e. GET multiple times)
# or direct, i.e. POST
$method = $ENV{'REQUEST_METHOD'};
if ($method eq "GET") {
$form_info = $ENV{'QUERY_STRING'};
print LOGFILE "Method found was: REQUEST_METHOD\n";
}
elsif ($method eq "POST"){
# Get the input
$data_size = $ENV{'CONTENT_LENGTH'};
read(STDIN,$form_info,$data_size);
print LOGFILE "\nMethod found was: POST\n";
}
else {
print "Client used unsupported method";
print LOGFILE "\nMethod found was: Client used unsupported method\n";
}
我的假设是,像这样的代码在小程序中使用:
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class PostMethodExample {
public static void main(String args[]) {
HttpClient client = new HttpClient();
client.getParams().setParameter("http.useragent", "Test Client");
BufferedReader br = null;
PostMethod method = new PostMethod("http://search.yahoo.com/search");
method.addParameter("p", "\"java2s\"");
try{
int returnCode = client.executeMethod(method);
if(returnCode == HttpStatus.SC_NOT_IMPLEMENTED) {
System.err.println("The Post method is not implemented by this URI");
// still consume the response body
method.getResponseBodyAsString();
} else {
br = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));
String readLine;
while(((readLine = br.readLine()) != null)) {
System.err.println(readLine);
}
}
} catch (Exception e) {
System.err.println(e);
} finally {
method.releaseConnection();
if(br != null) try { br.close(); } catch (Exception fe) {}
}
}
}