下面是一段试图发布到本地服务器上的PHP脚本的代码片段.我正在将数据传回服务器的MySQL表,因为数据量非常小,我想我会使用HttpClient将数据嵌入到URL参数中.
但是,即使我从服务器获得的响应是正常的(HTTP代码= 200),很明显服务器端PHP脚本没有获得正确格式化的数据(对MySQL表没有影响).但是,当我在浏览器中手动输入URL + args时,如下所示:
http://10.0.0.13/jobs_returndata_test.php?jobnum=189193&pnum=3&entime=13:00&extime=14:00
Run Code Online (Sandbox Code Playgroud)
例如,一切正常(PHP脚本正确写入MySQL表).
我的问题:我有没有办法真正查看HttpClient发送的内容?(即HttpPost对象的整个.toString内容?).这是Android端代码段:
// Create a new HttpClient and Post Header, send data as args to PHP file
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.0.13/jobs_returndata.php");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("jobnum",convertSimple(jobNum)));
nameValuePairs.add(new BasicNameValuePair("pnum",convertSimple(rowNum)));
nameValuePairs.add(new BasicNameValuePair("entime",enteredInTime));
nameValuePairs.add(new BasicNameValuePair("extime",enteredOutTime));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
Log.i("HTTP Post", "Execute Post sending jobnum="+ convertSimple(jobNum) +
"&pnum="+ convertSimple(rowNum) + "&entime=" + enteredInTime
+ "&extime=" + enteredOutTime);
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
Log.i("HTTP Post", "Response …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用curl对应用程序进行POST.我想用文件中的内联数据和数据构建数据,但我无法做到.
有谁知道这是否可能?
这是我正在尝试的代码示例:
curl -i -X POST http://localhost:3000/admin/articles -H "Content-Type: application/json" --data '{"article": {"issue_id": "1", "title": "hello", "translations_attributes": {"0": {"locale": "en", "id": "", "content": @file.json}}}}'
Run Code Online (Sandbox Code Playgroud) 我是新手使用R发布表单然后从网上下载数据.我有一个问题可能很容易让那里的人发现我做错了什么,所以我感谢你的耐心等待.我有一台Win7 PC和Firefox 23.x是我的典型浏览器.
我正在尝试发布显示的主要表单
我有以下R脚本:
your.username <- 'username'
your.password <- 'password'
setwd( "C:/Users/Desktop/Aplia/data" )
require(SAScii)
require(RCurl)
require(XML)
agent="Firefox/23.0"
options(RCurlOptions = list(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl")))
curl = getCurlHandle()
curlSetOpt(
cookiejar = 'cookies.txt' ,
useragent = agent,
followlocation = TRUE ,
autoreferer = TRUE ,
curl = curl
)
# list parameters to pass to the website (pulled from the source html)
params <-
list(
'userAgent' = agent,
'screenWidth' = "",
'screenHeight' = "",
'flashMajor' = "",
'flashMinor' …Run Code Online (Sandbox Code Playgroud) 我想使用将文件(特定于图像)上传到REST服务器HTTP POST.我已经导入/添加到构建路径httpmime-4.3.1.jar和apache-mime4j-0.6.jar.我在堆栈跟踪中得到以下错误.
这有效吗? post.setHeader("enctype", "multipart/form-data");
HTTP POST代码
public void multiPartPost() throws ClientProtocolException, IOException {
File image = new File(EXTERNALSTORAGE + "/Pictures/sample.jpg");
FileBody fileBody = new FileBody(image);
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
post.setHeader("enctype", "multipart/form-data");
MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
multipartEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
multipartEntity.addPart("sampleImage", fileBody);
post.setEntity(multipartEntity.build());
HttpResponse response = client.execute(post);
String responseBody = EntityUtils.toString(response.getEntity());
Log.v("multiPartPost HTTP Response", responseBody);
}
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪
01-05 17:41:25.470: W/dalvikvm(6564): VFY: unable to resolve static field 1755 (DEFAULT_BINARY) in Lorg/apache/http/entity/ContentType;
01-05 …Run Code Online (Sandbox Code Playgroud) 我是Qt的新手,对于发送一个PHP文件请求并阅读响应有一些困难.
我在Qt 5中发现的关于如何实现POST请求的一切都在某种程度上已经过时(Qt 4.x)并且无法正常工作,或者因为缺乏知识而无法帮助我.
例如,php文件如下所示:
<?php
// read param1
$value = $_POST['param1'];
// Do some stuff here
// return some text
echo $value;
?>
Run Code Online (Sandbox Code Playgroud)
我想做的就是:
有一个小例子的c ++ - 代码,如何用QT5实现这个任务?
播放2.4.x. 我们如何才能将通过POST请求体发送的数据作为键值对?我正在发送邮递员插件的帖子请求,在正文中创建了一个关键值parit.
我怎么能从动作函数中获取这个值.我尝试使用request.body()但它无法单独从中获取值.
我有什么方法可以获得发布请求正文中发送的值
在Python Urllib中执行POST而不是GET时遇到问题.我跑3.5.我试图POST到形成字段.
我读到如果数据参数存在,urllib.request.Request将默认为POST.我在https://docs.python.org/3/howto/urllib2.html上看到了这个
我复制这些设置,当我启动wireshark时,我看到的是GET和Never a Post,即使看起来代码正在执行.
这是我的代码:
values = {"field1" : z[2:-1], "Submit":"Save"}
print(values)
data = urllib.parse.urlencode(values)
data = data.encode('utf-8')
print(data)
req = urllib.request.Request("http://www.randomsite.com/myprocessingscript.php", data)
with urllib.request.urlopen(req) as response:
the_page = response.read()
print(the_page)
Run Code Online (Sandbox Code Playgroud)
当我启动wireshark时,这是req行的结果:
GET /myprocessingscript.php HTTP/1.1 Accept-Encoding:identity主机:ec2-52-91-45-113.compute-1.amazonaws.com连接:close User-Agent:Python-urllib/3.5
HTTP/1.1 200 OK日期:2015年10月28日星期三02:47:22 GMT服务器:Apache/2.4.17(Unix)OpenSSL/1.0.1p PHP/5.5.30 mod_perl/2.0.8-dev Perl/v5.16.3 X-Powered-By:PHP/5.5.30内容长度:23连接:关闭内容类型:text/html
没有要处理的帖子数据
另外当我运行脚本时,这是我从print语句得到的:
{'Submit':'save','field1':'hostlab\chris'} b'Submit = Save&field1 = hostlab%5Cchris%5Cr%5Cn'b'no post post data to process'Trackback(最近一次呼叫最后):File "C:\ Users\chris\Desktop\test.py",第20行,time.sleep(random.randint(5,10))
他们正在访问两个Web文件.Index.html和myprocessingscript.php:
Index.html:
<h1>randomsite.com.</h1>
####<p>whoami</p>
<form action="myprocessingscript.php" method="POST">
<input name="field1" type="text" />
<input type="submit" name="submit" value="Save"> …Run Code Online (Sandbox Code Playgroud) 在我的Laravel(5.1)项目中,我需要创建一个验证表单的请求.
但是对于这个请求,我想合并两个不同的请求:
第一个要求:
class AdvertisementRequest extends Request {
public function authorize()
{
return true;
}
public function rules()
{
return [
'ads_type' => 'required|numeric|in:0,1',
'category' => 'required|numeric|exists:categories,id',
'title' => 'required|alpha_num|max:45',
'description' => 'required|alpha_num|max:2000',
'price' => 'required|numeric',
];
}
}
Run Code Online (Sandbox Code Playgroud)
第二个要求:
class UserRegisterRequest extends Request {
public function authorize()
{
return true;
}
public function rules()
{
$rules = [
'form_type' => 'required|numeric|in:0,1',
'user_type' => 'required|numeric|in:0,1',
'phone' => 'required|phone_number',
'region' => 'required|numeric|exists:regions,id',
'department' => 'required|numeric|exists:departments,code',
'postal_code' => 'required|postal_code',
'city' => 'alpha|max:45', …Run Code Online (Sandbox Code Playgroud) 我对用于表单的Post查询有问题.每次我尝试验证表单时都会出现"406不可接受"错误,而Object.data为空白.
var edit = function(form){
var token = window.localStorage.getItem('token');
$ionicLoading.show();
return $http({
method : 'POST',
url : API.url + '/user',
headers : {Authorization : 'Bearer ' + token},
transformRequest: function(data, headers){
console.log(headers);
headers = angular.extend({}, headers, {'Content-Type': 'application/json;charset=UTF-8'});
console.log(headers);
console.log(data);
console.log(angular.toJson(data));
return angular.toJson(data); // this will go in the body request
},
data : form
}).then(function(result) {
console.dir(result.data);
},function errorCallback(response) {
console.log(response);
});
Run Code Online (Sandbox Code Playgroud)
};
我不明白为什么不接受..
这是我使用Flask和Python的第一个应用程序.
我使用以下URL格式从Arduino发送POST请求到在Pythonanywhere服务器实例上运行的烧瓶应用程序.
有效的POST请求:3个URL参数 http://voyagers.pythonanywhere.com/senddata?node=1234&lat=18.5580&lng=73.8075
我需要通过以某种形式验证URL来阻止进一步处理的请求.我希望这可以保护我的应用程序免受未经身份验证的POST请求.
说这样的话:超过3个URL参数 http://voyagers.pythonanywhere.com/senddata?node=324&lat=18.5580&lng=73.8075&a=c&a=d
我怎样才能在Flask中实现这一目标?
还建议,如果有更好的方法可以用于保护未授权请求的应用程序.