标签: post

以JSON格式POST数据

我有一些数据需要转换为JSON格式,然后用JavaScript函数POST它.

<body onload="javascript:document.myform.submit()">
<form action="https://www.test.net/Services/RegistrationService.svc/InviteNewContact" method="post" name="myform">
  <input name="firstName" value="harry" />
  <input name="lastName" value="tester" />
  <input name="toEmail" value="testtest@test.com" />
</form>
</body>
Run Code Online (Sandbox Code Playgroud)

这是帖子现在的样子.我需要它以JSON格式提交值并使用JavaScript进行POST.

javascript post json xmlhttprequest

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

如何在POST表单上设置Header字段?

如何在提交表单时在POST标题中设置自定义字段?

html javascript post http-post httprequest

83
推荐指数
3
解决办法
14万
查看次数

如何在PHP CURL中从POST切换到GET

我尝试从之前的Post请求切换到Get请求.假设它是一个Get但最终会发布一个帖子.

我在PHP中尝试了以下内容:

curl_setopt($curl_handle, CURLOPT_POSTFIELDS, null);
curl_setopt($curl_handle, CURLOPT_POST, FALSE);
curl_setopt($curl_handle, CURLOPT_HTTPGET, TRUE);
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

附加信息:我已经建立了一个用于执行POST请求的连接.这成功完成但稍后当我尝试重用连接并使用上面的setopts切换回GET时,它仍然在内部使用不完整的POST头进行POST.问题是它认为它正在执行GET但最终放置一个没有content-length参数的POST头,并且连接失败并出现411 ERROR.

php post curl get

82
推荐指数
4
解决办法
23万
查看次数

如何跳过AngularJS中的OPTIONS预检请求

我开发了一个PhoneGap应用程序,现在正在转换为移动网站.除了一个小小的故障外,一切顺利.我通过POST请求使用某个第三方API,这在应用程序中运行良好,但在移动网站版本中失败.

仔细看后,似乎AngularJS(我猜浏览器实际上)是先发送一个OPTIONS请求.我今天学到了很多关于CORS的知识,但我似乎无法弄清楚如何完全禁用它.我无权访问该API(因此无法进行更改),但他们已将我正在处理的域添加到其Access-Control-Allow-Origin标头中.

这是我正在谈论的代码:

        var request = {
                language: 'fr',
                barcodes: [
                    {
                        barcode: 'somebarcode',
                        description: 'Description goes here'
                    }
                ]
            };
        }
        var config = {
            headers: { 
                'Cache-Control': 'no-cache',
                'Content-Type': 'application/json'
            }
        };
        $http.post('http://somedomain.be/trackinginfo', request, config).success(function(data, status) {
            callback(undefined, data);
        }).error(function(data, status) {
            var err = new Error('Error message');
            err.status = status;
            callback(err);
        });
Run Code Online (Sandbox Code Playgroud)

如何阻止浏览器(或AngularJS)发送OPTIONS请求并跳转到实际的POST请求?我正在使用AngularJS 1.2.0.

提前致谢.

post cors angularjs

82
推荐指数
3
解决办法
10万
查看次数

从没有javascript的HTML表单发布数组

我有一个有点复杂的表单,我希望通过本地POST一组元组来简化服务器端(PHP)处理.

表单的第一部分代表用户:

  • 名字
  • 电子邮件
  • 地址
  • 等等

表单的第二部分代表:

  • 水果
  • 高度
  • 等等

问题是我需要能够以相同的形式为单个用户 POST多个.我希望将信息作为单个用户发送给一组树,但这可能与表单太复杂.我唯一想到的是使用javascript创建一些带有User对象和Tree对象数组的JSON消息.但是,避免使用javascript来支持更多用户(有些人关闭脚本)会很不错.

html forms post

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

使用Rails link_to获取发布的链接

我有一个链接,我需要提交一个帖子请求.通常,我会使用jQuery并阻止链接的默认行为,然后将表单提交到目标.这似乎是Rails应该能够帮助我的东西.果然,该link_to方法有一个指定POST http方法的选项:

link_to "Profile", 'http://example.com/profile', method: :post
Run Code Online (Sandbox Code Playgroud)

这有效,但我也需要添加2个参数.我试过了:

link_to "Profile", 'http://example.com/profile', method: post, param1: 'value1', param2: 'value2'
Run Code Online (Sandbox Code Playgroud)

这只是将这些参数添加到<a>HTML元素中,但是在单击链接时没有提交这些参数:

<a rel="nofollow" param1="value1" param2="value2" data-method="post" href="http://example.com/profile">Profile</a>
Run Code Online (Sandbox Code Playgroud)

有没有办法使用参数link_to或任何其他Rails方法执行POST请求?我正在使用Rails 3.2.9.

post ruby-on-rails link-to ruby-on-rails-3 ruby-on-rails-3.2

79
推荐指数
4
解决办法
8万
查看次数

jQuery - 使用发布数据重定向

如何使用发布数据重定向?

如何移动到新页面$_POST

这该怎么做?它是如何完成的,为什么要这样做呢

html javascript jquery post

77
推荐指数
3
解决办法
14万
查看次数

在Flask应用程序中提交表单时,错误请求错误的原因是什么?

在阅读了许多类似的声音问题和相关的Flask文档之后,我似乎无法弄清楚在提交表单时会产生以下错误:

400错误请求

浏览器(或代理)发送了此服务器无法理解的请求.

虽然表单总是正确显示,但当我提交与这些函数中的任何一个相关联的HTML表单时,会发生错误请求:

@app.route('/app/business', methods=['GET', 'POST'])
def apply_business():
    if request.method == 'POST':    
        new_account = Business(name=request.form['name_field'], email=request.form['email_field'], account_type="business", 
            q1=request.form['q1_field'], q2=request.form['q2_field'], q3=request.form['q3_field'], q4=request.form['q4_field'], 
            q5=request.form['q5_field'], q6=request.form['q6_field'], q7=request.form['q7_field'],
            account_status="pending", time=datetime.datetime.utcnow())
        db.session.add(new_account)
        db.session.commit()
        session['name'] = request.form['name_field']    
        return redirect(url_for('success'))
    return render_template('application.html', accounttype="business")          

@app.route('/app/student', methods=['GET', 'POST'])
def apply_student():    
    if request.method == 'POST':    
        new_account = Student(name=request.form['name_field'], email=request.form['email_field'], account_type="student", 
            q1=request.form['q1_field'], q2=request.form['q2_field'], q3=request.form['q3_field'], q4=request.form['q4_field'], 
            q5=request.form['q5_field'], q6=request.form['q6_field'], q7=request.form['q7_field'], q8=request.form['q8_field'], 
            q9=request.form['q9_field'], q10=request.form['q10_field'],
            account_status="pending", time=datetime.datetime.utcnow())
        db.session.add(new_account)
        db.session.commit()
        session['name'] = request.form['name_field']    
        return redirect(url_for('success')) 
    return render_template('application.html', accounttype="student")
Run Code Online (Sandbox Code Playgroud)

HTML的相关部分是

<html>
<head>
    <title>apply</title>
</head>
<body>
    {% …
Run Code Online (Sandbox Code Playgroud)

python forms post bad-request flask

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

错误415不支持的媒体类型:如果是JSON,则POST不会到达REST,但如果是XML则不会

我实际上是REST WS的新手,但我真的不明白415 Unsupported Media Type.

我正在使用Firefox上的Poster测试我的REST,GET对我来说工作正常,但是POST(当它是a时application/xml)但是当我尝试application/json它根本没有到达WS时,服务器拒绝它.

这是我的URL:http:// localhost:8081/RestDemo/services/customers/add

这是JSON我发送的:{"name": "test1", "address" :"test2"}

这是XML我发送的:

<customer>
    <name>test1</name>
    <address>test2</address>
</customer>
Run Code Online (Sandbox Code Playgroud)

这是我的资源类:

@Produces("application/xml")
@Path("customers")
@Singleton
@XmlRootElement(name = "customers")
public class CustomerResource {

    private TreeMap<Integer, Customer> customerMap = new TreeMap<Integer, Customer>();

    public  CustomerResource() {
        // hardcode a single customer into the database for demonstration
        // purposes
        Customer customer = new Customer();
        customer.setName("Harold Abernathy");
        customer.setAddress("Sheffield, UK");
        addCustomer(customer);
    }

    @GET
    @XmlElement(name = …
Run Code Online (Sandbox Code Playgroud)

java rest post json web-services

74
推荐指数
4
解决办法
36万
查看次数

使用php发送json帖子

我有这些数据:

{ 
    userID: 'a7664093-502e-4d2b-bf30-25a2b26d6021',
    itemKind: 0,
    value: 1,
    description: 'Saude',
    itemID: '03e76d0a-8bab-11e0-8250-000c29b481aa'
}
Run Code Online (Sandbox Code Playgroud)

我需要发布到json网址: http:// domain/OnLeagueRest/resources/onleague/Account/CreditAccount

使用php如何发送此帖子请求?

php post json curl http-post

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