我们如何通过javascript发送请求使用HTTP POST方法...而无需提交表单?
我已经实现了一个通用的处理程序,作为ASP.Net中的一个宁静的Web服务.我在接收发布到此Web服务的XML文件时遇到问题.我实际上看不到任何被传递的东西.我已经浏览了请求对象的表单,查询字符串和文件属性.一切都是空的.我知道该文件已正确发布,因为我可以在使用端口嗅探器时看到它.
我该如何访问此文件?
本帖的问题正在继续.
我无法想象如何从主UI线程添加单独的线程来执行从服务器收集数据的工作.我之前从未做过线程,我认为我构造的类中的这个实例比我能找到的任何例子都要先进一点.
我的课程的任何帮助和发布的修订将不胜感激.
谢谢!
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
setContentView(R.layout.list_view2);
/**
* Get the query string from last activity and pass it to this
* activity-----------------------------------------------------
*/
String p = null;
if (extras != null) {
p = extras.getString(PHP_KEY);
}
loadQuery(p);
}
void loadQuery(String p) {
String qO = getIntent().getStringExtra("QUERY_ORDER");
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
// http post
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.2.2/App/php/" +
p + …Run Code Online (Sandbox Code Playgroud) 这是一个非常简单的表单,如下面的代码所示:
<form method="POST" action="news.php?nid=2">
<textarea id="txtcomment" style="width:100%; height: 70px;" maxlength="300"></textarea><br /><br />
<input type="submit" class="button" style="float: right; cursor:pointer;" value="Comment">
</form>
Run Code Online (Sandbox Code Playgroud)
但是在news.php中,我无法获得"txtcomment"的价值
echo $_POST['txtcomment'];
Run Code Online (Sandbox Code Playgroud)
什么也没有回报......
我想创建一个POST请求,将我的应用程序连接到具有Windows 8.1和C#的服务器.
我在microsoft API上看到POST请求必须在w8和w8.1之间使用不同的库http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh761504.aspx
如何创建IHTTPContent ?我不明白如何将字符串转换为此.
我应该用吗?HttpResponseMessage response = httpClient.PostAsync(uri,iHTTPContent)
我已经检查了类似的问题,但没有一个能解决我面临的问题。
我正在构建一个Web服务,我想从HTTP POST请求中检索XML数据,操纵数据并返回响应。编写脚本时应考虑以下信息:
The communication mode is HTTP POST (not SOAP)
The content type is text/xml.
The POST request will contain only XML
The request will be a RAW POST directly to stream and NOT in a parameter.
Run Code Online (Sandbox Code Playgroud)
我已经尝试过,但是我的脚本没有从HTTP POST请求中捕获数据。
我的脚本:
$postData = file_get_contents('php://input');
if(!empty($xml->MerchantReference)){
$merchRef = (string)$xml->MerchantReference;
$custRef = (int)$xml->CustReference;
$username = (string)$xml->ServiceUsername;
$password = (string)$xml->ServicePassword;
$db->setQuery(Check if customer exists in database);
if($db->countResultset() == 0)
{
header("Content-type: text/xml");
echo "<?xml version='1.0' encoding='UTF-8'?>";
echo "<CustomerInformationResponse>";
echo "<MerchantReference>".$merchRef."</MerchantReference>";
echo "<Customers>";
echo …Run Code Online (Sandbox Code Playgroud) 我工作的公司有一个旧的VB6应用程序,他们想强制使用TSL而不是SSL.我查看了代码,告诉他们应该没问题.该代码使用HTTPS向客户端网站发布帖子.它没有指定要使用的加密.
这是相关代码:
Sub PostXML()
Dim XMLHttpRequest As MSXML2.XMLHTTP
Dim TempString As String
Dim strURL As String
Dim strArgs As String
strURL = gPostWebServer & "/" & gPostFile
'ARB 1/8/2004 This is to trap if send fails and allow it to continue.
On Error GoTo errorHandler:
If Not XMLHttpRequest Is Nothing Then Set XMLHttpRequest = Nothing
Set XMLHttpRequest = New MSXML2.XMLHTTP
strArgs = "?Username=" & gPostUserName & "&Password=" & gPostPassword
XMLHttpRequest.Open "POST", strURL & strArgs, False
XMLHttpRequest.send dom_GlobalXMLObject
If XMLHttpRequest.Status >= …Run Code Online (Sandbox Code Playgroud) 我试图通过Jsoup发出这个http请求:http://api.decarta.com/v1/[KEY]/batch?requestType=geocode如此处所示.这是我的相同代码:
String postUrl=postURLPrefix+apiKey+"/batch?requestType=geocode";
System.out.println(postUrl);
String response= Jsoup.connect(postUrl).timeout(60000).ignoreContentType(true)
.header("Content-Type", "application/json;charset=UTF-8")
.method(Connection.Method.POST)
.data("payload",jsonPayload.toString())
.execute()
.body();
Run Code Online (Sandbox Code Playgroud)
jsonPayload.toString()给出了:
{"payload":["146 Adkins Street,Pretoria,Pretoria,Gauteng","484 Hilda Street,Pretoria,Pretoria,Gauteng","268 Von Willich Street,Centurion,Centurion,Gauteng","100 Lion Road,Pretoria,Pretoria,Gauteng","Poligoon Street,Pretoria,Pretoria,Gauteng","91 Hornbill Street,Pretoria,Pretoria,Gauteng","55 Eland Street,Pretoria,Pretoria,Gauteng","31 Pelican Avenue,Centurion,Centurion,Gauteng","308 The Hillside Street,Pretoria,Pretoria,Gauteng","8 Spekhout Avenue,Centurion,Centurion,Gauteng","108 Apiesdoring Street,Pretoria,Pretoria,Gauteng","521 Louis Trichardt Street,Pretoria,Pretoria,Gauteng","31 Leopard Road,Pretoria,Pretoria,Gauteng","648 Klippan Street,Pretoria,Pretoria,Gauteng","13 Sweetpea Avenue,Pretoria,Pretoria,Gauteng","232 Kemphaan Street,Centurion,Centurion,Gauteng","32 Cantonments Road,Centurion,Centurion,Gauteng","882 Burlington St,Roseville,Gauteng","15 Brits Street,Olympus Ridge Complex,Centurion,Gauteng","15 Brits Street,Monument Park,Centurion,Gauteng","35 De La Rey Road,Monument Park,Centurion,Gauteng","112 Diamond St,Monument Park,Klerksoord,Gauteng","Hendrik Verwoerd Drive,Lyttelton,Centurion,Gauteng","777 Gambry Avenue,Garsfontein,Pretoria,Gauteng","57 Pheasant Avenue,Waterkloof Rand Corporatepark,Akasia,Gauteng","18 …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过Android连接到REST服务器(我用Spark创建).我可以使用POSTMAN(Chrome Addon)发送POST-Requests并得到我想要的内容,但是当我尝试从我的Android设备发送POST请求时,我收到以下错误:
E/error: com.android.volley.NoConnectionError: java.net.ConnectException: failed to connect to /127.0.0.1 (port 4567) after 2500ms: isConnected failed: ECONNREFUSED (Connection refused)
Run Code Online (Sandbox Code Playgroud)
这是服务器部分:
Spark.post("/up", new Route()
{
public Object handle(Request req, Response res)
{
System.out.println(req.queryParams());
return "its something";
}
});
Run Code Online (Sandbox Code Playgroud)
这是Android的一部分:
public void sendHTTPRequest()
{
RequestQueue MyRequestQueue = Volley.newRequestQueue(this);
String url = "http://127.0.0.1:4567/up";
StringRequest MyStringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
//This code is executed if the server responds, whether or not the response contains data. …Run Code Online (Sandbox Code Playgroud) 我正在为我的项目使用"hackathon-starter"节点束.在此构建中,当我尝试从request.post调用API时,它将采用" 'application/x-www-form-urlencoded;charset=utf-8'所有API的内容类型标头.我已尝试从API调用更改标头,但它只需要
内容类型:'application/x-www-form-urlencoded; charset = utf-8'
所有API的标头.我试过下面的代码.我想为所有API 设置application/json.
var querystring = require('querystring');
var request = require('request');
var form = {
"userType": req.body.type,
"userName": req.body.mobile,
"email": req.body.email,
"name": req.body.name,
"password": req.body.password
};
var formData = querystring.stringify(form);
var contentLength = formData.length;
request.post({
headers: {'content-type':'application/json'},
url:'mylink',
form: formData // I have tried form as well.
},function(error, response, body){
console.log(body)
});
Run Code Online (Sandbox Code Playgroud)
我在控制台上的错误消息.
{"timestamp":1484822264270,"status":415,"error":"Unsupported Media Type","exception":"org.springframework.web.HttpMediaTypeNotSupportedException","message":"Content type 'application/x-www-form-urlencoded;charset=utf-8' not supported","path":"mylink"}
Run Code Online (Sandbox Code Playgroud)