gpt4 book ai didi

asp.net - http POST 与 asp.net

转载 作者:可可西里 更新时间:2023-11-01 17:16:08 25 4
gpt4 key购买 nike

我有一个烦人的 ASP.NET 问题:

我有一个 Perl 脚本(见下文),它获取 form_info 变量。不幸的是,现在是 http POST,而不是 http GET,所以 Request.Querystring 不起作用...

现在我必须用 asp.net 页面/应用程序替换 Perl 脚本,但我的问题是当我没有字符串时我无法处理字符串 form_info...而且我无法将 http POST 更改为 HTTP get,因为它是由第 3 方 java 小程序生成的。

# 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) {}
}

}
}

最佳答案

你不能只使用Request.Form吗?而不是 Request.QueryString

例如:

string p = Request.Form["p"];    // should contain "java2s" in your example

关于asp.net - http POST 与 asp.net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1393840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com