标签: http-post

MVC中的HttpPost vs HttpGet属性:为什么要使用HttpPost?

所以我们有[HttpPost],它是一个可选属性.据我所知,这会限制调用,因此只能通过HTTP POST请求进行调用.我的问题是为什么我要这样做?

asp.net-mvc attributes http-get http-post

40
推荐指数
3
解决办法
9万
查看次数

如何将json添加到java中的http帖子的主体

我正在尝试在java中为我正在处理的Android应用发布一些JSON数据.以下是有效的还是我需要以不同的方式推送JSON字符串?

HttpPost httpost = new HttpPost("http://test.localhost");
httpost.setEntity(new StringEntity("{\"filters\":true}"));
httpost.setHeader("Accept", "application/json");
httpost.setHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
//... other java code to execute the apache httpclient
Run Code Online (Sandbox Code Playgroud)

先感谢您

java android json httpclient http-post

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

Node.js - 如何从html发送数据到express

这是html中的表单示例:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>CSS3 Contact Form</title>
</head>
<body>
<div id="contact">
    <h1>Send an email</h1>
    <form action="/myaction" method="post">
        <fieldset>
            <label for="name">Name:</label>
            <input type="text" id="name" name="name" placeholder="Enter your full name" />

            <label for="email">Email:</label>
            <input type="email" id="email" placeholder="Enter your email address" />

            <label for="message">Message:</label>
            <textarea id="message" placeholder="What's on your mind?"></textarea>

            <input type="submit" value="Send message" />

        </fieldset>
    </form>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

这是在服务器上运行的node.js函数:

var sys = require('sys'),
    http = require('http');
    http.createServer(function (req, res) {
            switch (req.url) 
                case '/myaction':
                        res.end(?????);
                    break;
            } …
Run Code Online (Sandbox Code Playgroud)

forms html5 http-post node.js node.js-client

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

如何用curl发布原始身体数据?

在您将此作为重复发布之前; 我已经尝试了很多关于SO的建议.

到目前为止,我一直在使用邮递员将数据发布到Java Web服务.这很好用如下:

在此输入图像描述

我现在想用curl做同样的事情,所以我尝试使用以下方法:

$ curl -X POST --data "this is raw data" http://78.41.xx.xx:7778/
$ curl -X POST --data-binary "this is raw data" http://78.41.xx.xx:7778/
$ curl -X POST --data "@/home/kramer65/afile.txt" http://78.41.xx.xx:7778/
$ curl -X POST --data-binary "@/home/kramer65/afile.txt" http://78.41.xx.xx:7778/
Run Code Online (Sandbox Code Playgroud)

不幸的是,所有这些都显示接收方空的原始身体.

有谁知道我在这里做错了什么?我的卷发请求与我的邮递员请求有什么不同?欢迎所有提示!

linux post curl http-post request

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

发送POST请求时,Django返回403错误

当我使用以下Python代码向我的Django网站发送POST请求时,我得到403:Forbidden错误.

url = 'http://www.sub.domain.com/'
values = { 'var': 'test' }

try:
    data = urllib.urlencode(values, doseq=True)
    req = urllib2.Request(url, data)
    response = urllib2.urlopen(req)
    the_page = response.read()
except:
    the_page = sys.exc_info()
    raise
Run Code Online (Sandbox Code Playgroud)

当我打开任何其他网站时,它正常工作.domain.com也是Django网站,也可以正常使用.我认为,这是Django配置问题,任何人都可以告诉我应该怎么做才能提供对我脚本的访问权限?

python django http-post http-status-code-403

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

JSON vs Form POST

我们正在就将数据发布到REST端点的问题进行一些讨论.由于对象非常复杂,最简单的解决方案是将它们序列化为JSON并在请求体中发送.

现在的问题是:这是犹太人吗?或者是否应将JSON设置为表格参数,如data = [JSON]?或者在请求体中发送JSON只是为了强迫客户端使用应用程序,通过JavaScript发送数据而不是让浏览器打包它application/x-www-form-urlencoded

我知道这三个选项都有效.但是,这是OK?或至少推荐

rest post json http-post

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

如何在curl请求的数据中发布URL

我试图发布两个参数,使用curl,pathfileName:

curl --request POST 'http://localhost/Service' --data "path='/xyz/pqr/test/'&fileName='1.doc'"
Run Code Online (Sandbox Code Playgroud)

我知道这有什么不对劲.我必须使用像URLEncode这样的东西.我尝试了许多东西仍然没有运气.

请举例说明如何在curl请求的数据中发布url.

linux bash curl web-services http-post

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

如何在java中发送Https Post请求

我想从java代码登录应用程序.这是我的代码......

String httpsURL = "https://www.abcd.com/auth/login/";

String query = "email="+URLEncoder.encode("abc@xyz.com","UTF-8"); 
query += "&";
query += "password="+URLEncoder.encode("abcd","UTF-8") ;

URL myurl = new URL(httpsURL);
HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
con.setRequestMethod("POST");

con.setRequestProperty("Content-length", String.valueOf(query.length())); 
con.setRequestProperty("Content-Type","application/x-www- form-urlencoded"); 
con.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0;Windows98;DigExt)"); 
con.setDoOutput(true); 
con.setDoInput(true); 

DataOutputStream output = new DataOutputStream(con.getOutputStream());  


output.writeBytes(query);

output.close();

DataInputStream input = new DataInputStream( con.getInputStream() ); 



for( int c = input.read(); c != -1; c = input.read() ) 
System.out.print( (char)c ); 
input.close(); 

System.out.println("Resp Code:"+con .getResponseCode()); 
System.out.println("Resp Message:"+ con .getResponseMessage()); 
Run Code Online (Sandbox Code Playgroud)

但我无法登录,它只返回登录页面.

如果有人可以,请帮助我理解我做错了什么.

java http-post httpurlconnection

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

使用curl --fail获取页面输出

调用没有参数的curl,我得到页面输出,即使http状态代码= 404:

$ curl http://www.google.com/linux;
<!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 404 (Not Found)!!1</title>
  <style>
    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/errors/logo_sm_2.png) no-repeat}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/errors/logo_sm_2_hr.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/errors/logo_sm_2_hr.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/errors/logo_sm_2_hr.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:55px;width:150px}
  </style>
  <a href=//www.google.com/><span id=logo aria-label=Google></span></a>
  <p><b>404.</b> <ins>That’s an error.</ins>
  <p>The requested URL <code>/linux</code> was not found on this server.  <ins>That’s all we know.</ins>

$ echo $?; …
Run Code Online (Sandbox Code Playgroud)

curl http wget http-post postfile

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

如何将纯文本发布到ASP.NET Web API端点?

我有一个ASP.NET Web API端点,其控制器操作定义如下:

[HttpPost]
public HttpResponseMessage Post([FromBody] object text)
Run Code Online (Sandbox Code Playgroud)

如果我的帖子请求正文包含纯文本(即不应该被解释为json,xml或任何其他特殊格式),那么我认为我可以在我的请求中包含以下标题:

Content-Type: text/plain
Run Code Online (Sandbox Code Playgroud)

但是,我收到错误:

No MediaTypeFormatter is available to read an object of type 'Object' from content with media type 'text/plain'.
Run Code Online (Sandbox Code Playgroud)

如果我将控制器操作方法签名更改为:

[HttpPost]
public HttpResponseMessage Post([FromBody] string text)
Run Code Online (Sandbox Code Playgroud)

我得到一个略有不同的错误消息:

No MediaTypeFormatter is available to read an object of type 'String' from content with media type 'text/plain'.
Run Code Online (Sandbox Code Playgroud)

text content-type http-post http-request asp.net-web-api

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