标签: http-post

“无法解析 URLEncoder” - URLEncoder.encode(p.getValue(),"UTF-8");

我见过使用它的相似代码,但我在这一行给了我这个错误“无法解析 URLEncoder”:

String paramString = p.getName() + "=" + URLEncoder.encode(p.getValue(),"UTF-8");

它说函数是 encode(String s, String enc) 在“enc”上它说要使用的编码方案。

我正在运行 Eclipse SDK 版本:3.6.1,但我不知道如何解决此错误。

eclipse rest android http-post

1
推荐指数
1
解决办法
5224
查看次数

获取 POST 端点以在自托管 (WebServiceHost) C# web 服务中工作?

所以,我一直在搞 webservices 一段时间,我一直回到一些基础知识,我似乎永远不会正确。

问题 1:

在 .NET/C# 中使用 WebServiceHost 时,您可以使用 GET/POST/etc 定义方法/端点。设置一个 GET 方法很容易,而且它的工作方式非常直接,而且很容易理解它是如何工作的。例如:

[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "/PutMessage/{jsonString}", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
string PutMessage(string jsonString);
Run Code Online (Sandbox Code Playgroud)

如果我调用 http:///MyWebService/PutMessage/{MyJsonString} 我会通过该方法,并且一切都很好(或多或少)。

但是,当我将其定义为POST时,这意味着什么?

[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "/PutMessage/{jsonString}", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
string PutMessage(string jsonString);
Run Code Online (Sandbox Code Playgroud)

UriTemplate 在这里做什么?如果我执行 POST,我希望数据不包含在 URI 中,而是包含在帖子的“数据部分”中。但是我是否在数据部分定义了变量名?WebServiceHost/.NET 如何知道帖子的“数据部分”中包含的内容要放入变量 jsonString 中?我如何从客户端(不是 C#,我们说 JQuery)发布数据,以便在服务器端正确解释它?

(WebMessageFormat 是如何影响事物的?我到处都读过这方面的内容(MSDN、Stackoverflow 等),但还没有找到明确而好的答案。)

问题2:

在我试图理解这一点时,我想我会制作一个非常简单的 POST 方法,如下所示:

[OperationContract]
[WebInvoke]
string PutJSONRequest(string …
Run Code Online (Sandbox Code Playgroud)

c# wcf web-services http-post webservicehost

1
推荐指数
1
解决办法
6946
查看次数

正确的方法将JSON数据从Android发布到PHP

我已经看到很多教程和问题使用以下方法从Android发送JSON对象到PHP.例如这个wordpress博客,这个代码项目教程和stackoverflow上的一些答案就像这些.

所有这些教程和答案都使用HTTP标头将数据(正文)发送到PHP.

....
// Post the data:
httppost.setHeader("json",json.toString());
....
Run Code Online (Sandbox Code Playgroud)

作为程序员,我们都知道标题不是为了携带数据(正文).标题应该只包含元数据.

那么,有没有一种正确的方法从Android发送JSON数据到PHP,而不涉及在头文件中设置数据?

php android json http-post http-headers

1
推荐指数
1
解决办法
2万
查看次数

如何将 POST 数据发送到反向 url

我有HttpResponseRedirect()构造所需网址的函数:

我的create观点:

def create(request):
    entry = Char_field(field=request.POST['record'])
    entry.save()
    return HttpResponseRedirect(reverse('db:index_page',kwargs={'redirected':'true'}))
Run Code Online (Sandbox Code Playgroud)

HttpResponseRedirect()重定向到的视图是:

def index(request):
    redirected = False
    template= 'app/index.html'
    try:
        if request.POST['redirected'] is 'true':
            redirected = True
    except:
        pass
    return render(request,template,{'redirected':redirected})
Run Code Online (Sandbox Code Playgroud)

但是它返回一个错误:

NoReverseMatch at /app/create/
Reverse for 'index_page' with arguments '()' and keyword arguments '{'redirected': 'true'}' not found.
Run Code Online (Sandbox Code Playgroud)

网址.py:

urlpatterns = patterns('',
    url(r'^$',views.index,name='index_page'),
    url(r'^get_record/$',views.get_record,name='get_record'),
    url(r'^create/$',views.create_html,name='create_path'),
    url(r'^add/$',views.create,name='add_record')
)
Run Code Online (Sandbox Code Playgroud)

为什么会这样,是否可以通过函数将POST数据发送到index_page视图reverse()

python django http-post python-2.7

1
推荐指数
1
解决办法
2431
查看次数

html 选择值 0 在 php 验证中始终为空

我尝试发布选定的值并检查变量是否为空。

html:

<select id="monitors-old" class="form-control" name="monitors-old">
   <option value="">Auswählen...</option>
   <option value="0" <?php if ($personData["cmo_mon"] == "0"){echo 'selected';}?>>0</option>
   <option value="1" <?php if ($personData["cmo_mon"] == "1"){echo 'selected';}?>>1</option>
   <option value="2" <?php if ($personData["cmo_mon"] == "2"){echo 'selected';}?>>2</option>
   <option value="3" <?php if ($personData["cmo_mon"] == "3"){echo 'selected';}?>>3</option>
   <option value="4" <?php if ($personData["cmo_mon"] == "4"){echo 'selected';}?>>4</option>
</select>
Run Code Online (Sandbox Code Playgroud)

结果 html:

<select id="monitors-old" class="form-control" name="monitors-old">
   <option value="">Auswählen...</option>
   <option value="0" selected="">0</option>
   <option value="1">1</option>
   <option value="2">2</option>
   <option value="3">3</option>
   <option value="4">4</option>
</select>
Run Code Online (Sandbox Code Playgroud)

邮政检查:

if (empty($_POST["monitors-old"])) {
   $errors[] = "Alt-Monitore is required.";
   die;
} …
Run Code Online (Sandbox Code Playgroud)

php http-post validate-request

1
推荐指数
1
解决办法
8670
查看次数

为什么我不能在POST中使用#(Number Sign)作为值(php页面)

我有一个php项目,我必须将文件名作为POST请求传递给web服务器中的文件.但是当我传递包含#(Number Sign)的文件名时,它无法获得正确的文件名,从而产生错误.

这是我简单的PHP脚本

<?php
$file = $_GET["file"];
if (!unlink("upload/".$file))
  {
  echo ("Error deleting $file");
  }
else
  {
  echo ("Deleted $file");
  }
?>
Run Code Online (Sandbox Code Playgroud)

php post http-post

1
推荐指数
1
解决办法
98
查看次数

Python脚本将图像发送给PHP

美好的一天.有人可以帮助我.我的任务是创建一个将图像发送到php(服务器端)的python脚本(客户端).

注意:python脚本在不同的raspberry pi中运行,php服务器只通过Internet接收图像.

成就:我现在可以从客户端向服务器发送文本数据.

问题:我的大问题是如何发送图像?

任何意见和建议非常感谢.谢谢.

我的Python脚本:

import urllib2
from urllib import urlencode 

# 192.168.5.149 is the ip address of server
url = "http://192.168.5.149/server/server.php"
data = {'test':'OK'}

encoded_data = urlencode(data)

website = urllib2.urlopen(url, encoded_data)
print website.read()
Run Code Online (Sandbox Code Playgroud)

我的PHP脚本:

<?php
echo $_POST['test'];
?>
Run Code Online (Sandbox Code Playgroud)

当我运行python脚本时,我得到了"ok"作为PHP服务器的发送.这意味着,连接成功.

EDITED

Python客户端:

import requests
url = 'http://messi-fan.org/post'
files = {'file': open('image.png', 'rb')}
r = requests.post(url, files=files)
Run Code Online (Sandbox Code Playgroud)

PHP服务器:

<?php
$file_path = "C:\\xampp\htdocs\server\php\\";

$file_path = $file_path.basename( $_FILES['file']['name']);
?>
Run Code Online (Sandbox Code Playgroud)

php python webserver file-upload http-post

1
推荐指数
1
解决办法
1万
查看次数

从小程序向服务器发布细节字节数组

在Grails Web应用程序中,我试图使用rest API将小鸟(指纹)字节数组从applet发布到服务器.

这是我试过的

private String post(String purl,String customerId, byte[] regMin1,byte[] regMin2) throws Exception {
    StringBuilder parameters = new StringBuilder();
    parameters.append("customerId=");
    parameters.append(customerId);
    parameters.append("&regMin1=");
    parameters.append(URLEncoder.encode(new String(regMin1),"UTF-8"));
    parameters.append("&regMin2=");
    parameters.append(URLEncoder.encode(new String(regMin2),"UTF-8"));
    URL url = new URL(purl); 
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();           
    connection.setDoOutput(true);
    connection.setDoInput(true);
    connection.setRequestMethod("POST"); 
    connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 
    connection.setRequestProperty("Content-Length",Integer.toString(parameters.toString().getBytes().length));

    DataOutputStream wr = new DataOutputStream(connection.getOutputStream ());
    wr.writeBytes(parameters.toString());
    wr.flush();
    wr.close();
    BufferedReader in = new BufferedReader(new InputStreamReader(
                                connection.getInputStream()));
    StringBuilder builder = new StringBuilder();
    String aux = "";

    while ((aux = in.readLine()) != null) {
        builder.append(aux);
    }
    in.close();
    connection.disconnect(); …
Run Code Online (Sandbox Code Playgroud)

java grails applet http-post fingerprint

1
推荐指数
1
解决办法
379
查看次数

是否可以通过 Post/Get 传递 Null 值?(PHP)

是否可以通过 Post/Get 传递 Null 值?

通过 null,我的意思是在 上返回 trueisset()但在 上返回false 的东西empty()

原因是,我想知道我是否需要额外检查$_GET我在哪里检查以下内容:

if (isset() && !empty()) {
    // do stuff
} elseif (isset() && empty()) {  // In other words, omit this one.
    // do other stuff
} else {
    //foo bar
}
Run Code Online (Sandbox Code Playgroud)

谢谢,

php get http-post

1
推荐指数
1
解决办法
1920
查看次数

Swift dataTaskWithRequest完成块未执行

我有一个函数,它将字典发回服务器,并在出现错误时返回状态代码或错误内容.它有时工作正常,而其余的时间则跳过完成部分.

func postData(url: String, query: NSDictionary) ->NSObject? {
   var error: NSError?
   var result: NSObject? = nil

   let dest = NSURL("http://myUrl.com")
   let request = NSMutableURLRequest(URL: dest!)
   request.HTTPMethod = "POST"
   request.HTTPBody = NSJSONSerialization.dataWithJSONObject(query, options: NSJSONWritingOptions.allZeros, error: &err)
   request.addValue("application/json", forHTTPHeaderField: "Content-Type")
   request.addValue("application/json", forHTTPHeaderField: "Accept")

   let task = NSURLSession.sharedSession().dataTaskWithRequest(request){
              data, response, error in
              if(error != nil){
                   println(error)
                   result = error 
                   return
              }
              result = (response as! NSHTTPURLResponse).statusCode
              return
    }
    task.resume()
    return result
}
Run Code Online (Sandbox Code Playgroud)

我提到NSURLSession dataTaskWithRequest没有被调用,并且知道它可能是由执行时间延迟引起的.但是,由于我需要状态代码(到目前为止返回nil)来确定帖子后要执行的操作,我想知道如何解决这个问题?

http-post nsurlsession swift

1
推荐指数
1
解决办法
4401
查看次数