我有HTML表单,用于从应用程序发送bug报告到服务器.我需要以编程方式模仿这种行为.相应的POST请求(或一系列请求)是什么样的?
<form name="bugreport" method="post" enctype="multipart/form-data" action="http://my-server.com/bugreport.php">
<div name="SentData">
<textarea name="logfile" class="UserVisible"></textarea><br>
<textarea name="configfile" class="UserVisible"></textarea><br>
</div>
<textarea name="usercomment" class="invisible"></textarea><br>
<input name="useremail" type="text" class="invisible">
<input class="invisible" type="submit" value="Send">
</form>
Run Code Online (Sandbox Code Playgroud) 如何在android中更改HttpPost的内容类型?
对于请求,我需要将内容类型设置为application/x-www-form-urlencoded
所以我得到了这段代码:
httpclient=new DefaultHttpClient();
httppost= new HttpPost(url);
StringEntity se = new StringEntity("");
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/x-www-form-urlencoded"));
httppost.setEntity(se);
Run Code Online (Sandbox Code Playgroud)
但这并没有成功,我无法在任何地方找到解决方案.
干杯
我有一个小的C#web应用程序.如何获得允许用户通过HTTP POST发送文件的c#代码.它应该能够发送文本文件,图像文件,excel,csv,doc(所有类型的文件)而不使用流阅读器和所有.
我有这样的请求:
$http({
method: 'POST',
url: '/url/',
data: 'test=data'
})
Run Code Online (Sandbox Code Playgroud)
在我的django观点中:
class SomeClass(View):
def get(self, request):
return HttpResponse("Hello")
def post(self, request):
print request.post
print request.body
return HttpResponse("Done")
Run Code Online (Sandbox Code Playgroud)
所以,当我这样做时,request.POST 我得到一个空的查询字典:<QueryDict: {}>
但我request.body有:test=data
所以我相信django将数据作为url编码的参数而不是字典接收.
如何以JSON/Dict发送或接收此数据?
我在MVC中有一个问题.
目前我在MVC工作,版本是MVC4.我有2个ActionResult方法,见下文
[HttpGet]
public ActionResult About()
{
ViewBag.Message = "Your app description page.";
return View();
}
[HttpPost]
public ActionResult About(ModelName ccc)
{
ViewBag.Message = "Your app description page.";
return View();
}
Run Code Online (Sandbox Code Playgroud)
我们需要[HttpPost]和[HttpGet]属性的using System.Web.Mvc;命名空间 .所以我在控制器中添加了命名空间.但我需要在我的控制器中为httpsresponseexpection错误处理添加另一个命名 空间.我在命名空间中添加了.这时候不行.using System.Web.Mvc;using System.Web.Http;System.Web.Mvc;
我收到此错误:无法找到类型或命名空间名称'HttpGet'.为什么?HttpGet的System.Web.Mvc和System.Web.Http之间的任何关系?
本org.apache.http类和AndroidHttpClient类已经被弃用的Android 5.1.这些类不再被维护,您应该尽快使用这些API将任何应用程序代码迁移到URLConnection类.
https://developer.android.com/about/versions/android-5.1.html#http
它建议切换到URLConnection类.没有足够的文件记录如何从应用程序进行发布呼叫.
目前我正在使用这个
public void postData()
{
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php");
try
{
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair(2);
nameValuePairs.add(new BasicNameValuePair("id", "12345"));
nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
}
catch (ClientProtocolException e)
{
// TODO Auto-generated catch block
}
catch (IOException e)
{
// TODO …Run Code Online (Sandbox Code Playgroud) 我有以下问题.Web服务正在向我的应用程序发送JSON POST请求,我想解析它.
我以为我可以用它来访问参数
@var = params[:name_of_the_JSON_fields]
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我在Heroku日志中看到,请求已完成且参数已存在,但我无法存储它们.
有没有人有想法?
我已经对使用HTTP POST发送数据的一些代码进行了故障排除,并且应该返回其内容为字典的JSON结果.我使用XML-RPC包装器来公开此服务.当包装器从http响应变量接收dict信息时,dict内容以这种形式包含在字符串中:
{'created': datetime.datetime(2010, 12, 31, 19, 13, 8, 379909), 'worker': u'GoogleWorker', 'ready': False, 'request_id': '8f1381853a444a42a37ae5152a3af947', 'owner': u'admin', 'shortname': u'test19'}
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用以下语句将下面的字符串转换为JSON结果:
result = json.loads(response[1])
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用json.loads将数据转换为JSON时,我收到以下错误: Fault: <Fault 1: "<type 'exceptions.ValueError'>:Expecting property name: line 1 column 1 (char 1)">
我手动尝试将上面的字符串转换为JSON,但我得到了同样的错误.这个词典在某种程度上是不正确的吗?是unicode吗?我也尝试将语言环境设置为UTF-8,但这不成功.
任何帮助将不胜感激.
我正在尝试调试我试图从列表应用程序发送的http帖子.我已经能够从php CURL发送正确的帖子,它与我的drupal 7网站核心接口并上传图像.
为了让这个在我的lisp应用程序中工作,我真的需要看到我的http帖子的内容正文,我已经能够使用这样的调用看到标题:
curl_setopt($curl, CURLOPT_STDERR, $fp);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
Run Code Online (Sandbox Code Playgroud)
我的lisp应用程序中的标题看起来相同,但我无法检查帖子的正文.我在网上搜索过,其他人也问了这个问题,但没有人发布回复.
我的http帖子的内容类型是:
application/x-www-form-urlencoded
Run Code Online (Sandbox Code Playgroud)
我也尝试了许多http代理debuging工具,但他们只有http GET来获取我的php页面,但从来没有捕获一旦php代码执行后从服务器发送的get.
编辑:我添加了一个代码snipet,显示我实际上传图像文件的位置.
// file
$file = array(
'filesize' => filesize($filename),
'filename' => basename($filename),
'file' => base64_encode(file_get_contents($filename)),
'uid' => $logged_user->user->uid,
);
$file = http_build_query($file);
// REST Server URL for file upload
$request_url = $services_url . '/file';
// cURL
$curl = curl_init($request_url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded'));
curl_setopt($curl, CURLOPT_STDERR, $fp);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_POST, 1); // Do a regular HTTP POST
curl_setopt($curl, CURLOPT_POSTFIELDS, $file); // Set POST data …Run Code Online (Sandbox Code Playgroud) 我已经看到这个问题浮现在互联网上,但我还没有找到一个有效的解决方案.基本上,我想加载我的应用程序并按下按钮; 然后按钮操作将在已经加载到webview中的网站中填写用户名和密码(或等待onPageFinished).最后,将激活登录页面上的提交按钮.
根据我的理解,这可以通过使用loadUrl(javascript)进行java注入来完成,但我不知道java命令将填充哪些字段.iOS的问题也是一样,但命令略有不同.
是否有可能在webivew中使用javascript做我要求的事情,或者我是否必须在没有像这样或这样的webview的情况下做一个http-post ?
非常感谢您提供的任何帮助!