Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Forms 通过post向webservice发送html表单_Forms_Html_Post - Fatal编程技术网

Forms 通过post向webservice发送html表单

Forms 通过post向webservice发送html表单,forms,html,post,Forms,Html,Post,我对HTML5开发非常陌生,这个问题可能非常愚蠢,但我已经找到了答案(或者我搜索得非常好) 我想通过post向web服务发送表单(我不想在URL中显示所有字段) 我有两个问题: 我必须如何命名表单字段?如果我试图发送一个用户名,我想我必须将此测试作为ID放入保存该值的字段。 这是因为我很好奇。哪个是发送到web服务的帖子内容 这是我在搜索Internet时发现的一个示例: <FORM action="http://somesite.com/prog/adduser" method="po

我对HTML5开发非常陌生,这个问题可能非常愚蠢,但我已经找到了答案(或者我搜索得非常好)

我想通过post向web服务发送表单(我不想在URL中显示所有字段)

我有两个问题:

  • 我必须如何命名表单字段?如果我试图发送一个
    用户名
    ,我想我必须将此测试作为ID放入保存该值的字段。
  • 这是因为我很好奇。哪个是发送到web服务的帖子内容
  • 这是我在搜索Internet时发现的一个示例:

     <FORM action="http://somesite.com/prog/adduser" method="post">
        <P>
        <LABEL for="firstname">First name: </LABEL>
                  <INPUT type="text" id="firstname"><BR>
        <LABEL for="lastname">Last name: </LABEL>
                  <INPUT type="text" id="lastname"><BR>
        <LABEL for="email">email: </LABEL>
                  <INPUT type="text" id="email"><BR>
        <INPUT type="radio" name="sex" value="Male"> Male<BR>
        <INPUT type="radio" name="sex" value="Female"> Female<BR>
        <INPUT type="submit" value="Send"> <INPUT type="reset">
        </P>
     </FORM
    
    
    

    名字:
    姓氏:
    电邮:
    男性
    女性


    每个web服务都应该为您提供类似的内容,这些内容通常包含可用字段和可使用方法的规范。如果您要连接的Web服务具有url
    webservice.com
    ,请尝试
    webservice.com/wsdl
    以获取url


    检查此主题:

    视情况而定,您可以通过重定向向页面发送帖子(在.NET中,您可以这样处理):

    您还可以使用jQuery使用以下命令对同一页面进行ajax调用:

    var forename = $("input[name=\"forename\"]").val();
    var surname = $("input[name=\"surname\"]").val();
    
    $.ajax({
        url: "http://myurl/postpage.ashx",
        type: "POST",
        async: true, // set to false if you don't mind the page pausing while waiting for response
        cache: false,
        dataType: "json",
        data: "{ 'forename': '" + forename + "', 'surname': '" + surname + "' }",
        contentType: "application/json; charset=utf-8",
        success: function(data) {
            // handle your successful response here
        },
        error: function(xhr, ajaxOptions, thrownError) {
            // handle your fail response here
        }
    });
    
    您将以相同的方式在服务器端代码中处理post。这里需要注意的关键是,无论您输入什么作为输入元素的name属性,都会将其作为键/值对发布到接收URL。

    属性“name”是唯一的,以便将该参数传递到Servlet(或任何地方)。post方法然后加密消息并将其发送到Servlet

    <form method="post" action = "LoginServlet">
         Name: <input type="text" name="userName">
         Password: <input type="password" name="password"> 
    
        <input type="submit" name = "Login" class="button">
    </form>
    

    我在问我该如何发送这些字段。我想我必须在表格上设置一些东西来识别他们。顺便说一句,web服务还没有实现。看看这里:这一切都取决于web服务。如果它是[RESTAPI][1],您可以直接发布到它。[1] :对不起,我不明白您的意思:我必须如何命名表单字段?这取决于Web服务和Web服务的规范。你想连接什么Web服务?@DavidEverlöf“你想连接什么Web服务?”是什么意思?我还没有实现web服务,我必须向某人询问。你是在问它是REST、SOAP还是其他web服务?我不知道你也要实现自己的web服务,我以为你想与现有的web服务通信。你能告诉exmaple如何在(ASP.NET)web方法中检索键/值对吗?我有这样的方法:[WebMethod(Description=“tests the method.”]public void TestMethod(String APP_VERSION_CODE){//APP_VERSION_CODE应该是值还是什么?我不知道..}但我一直收到一个ReportSenderException
    var forename = $("input[name=\"forename\"]").val();
    var surname = $("input[name=\"surname\"]").val();
    
    $.ajax({
        url: "http://myurl/postpage.ashx",
        type: "POST",
        async: true, // set to false if you don't mind the page pausing while waiting for response
        cache: false,
        dataType: "json",
        data: "{ 'forename': '" + forename + "', 'surname': '" + surname + "' }",
        contentType: "application/json; charset=utf-8",
        success: function(data) {
            // handle your successful response here
        },
        error: function(xhr, ajaxOptions, thrownError) {
            // handle your fail response here
        }
    });
    
    <form method="post" action = "LoginServlet">
         Name: <input type="text" name="userName">
         Password: <input type="password" name="password"> 
    
        <input type="submit" name = "Login" class="button">
    </form>
    
    String userName = request.getParameter("userName");