0

我正在尝试使用 C# 控制台应用程序在内部发布此表单中的数据。但我不明白为什么它不起作用。下面是html页面的body标签内的表单。

<form method="POST" name="frogs_simple_vmf" action="frog_simple.php">

            <table BORDER="0" cellpadding="5" cellspacing="0" border="0" class="tbl">       

              <tr>
                    <td>
                       <select name='from' onchange='check_ns2(this.form)'>
                          <option value='Sub1'>Sub1</option>
                  <option value='Sub2'>Sub2</option>
                  <option value='Sub3'>Sub3</option>              
                          <option value='Sub4'>Sub4</option>              
                       </select>
                       &nbsp
                       <input type='text' name='spec_id' size='30'>
                    </td>
                  </tr>
                <tr>
                <td>
                <table WIDTH="400" BORDER="0" cellpadding="0" cellspacing="0" >     
                <tr>
                            <td WIDTH="150"><b><a href="javascript:popup('../help/help_avp_light_eu.htm#Run_option', '500', '300');" class="lbl">Run Option:</a></td>
                    <td><b><a href="javascript:popup('../help/help_avp_light_eu.htm#DCN_inter', '500', '300');" class="lbl">DCN Interpretation:</a></td>
                        </tr>
                </table>
                </td>           
                    <td><b><a href="javascript:popup('../help/help_avp_light_eu.htm#User_name', '500', '300');" class="lbl">User Name:</a></td>
                    </tr>
              <tr><td><select name='output' onchange='check_ns2(this.form)'>
               <option value='Va1'>Va2</option>
               <option value='Va2'>Va2</option>

                     </select>&nbsp&nbsp;&nbsp;&nbsp;<input type='text' name='build' size=6> (YYYYWW)</td>
            <td><input type='text' id="time1" name='username' size=12></td>
              </tr>
              <tr>
            <td  colspan="2" class="buttonRow"> 
              <input TYPE="HIDDEN" name="com_site" value="comvmf">
              <input TYPE="SUBMIT" name="Execute" VALUE="Submit" class="btn">&nbsp;
              <input TYPE="RESET" VALUE="Reset" class="btn">&nbsp;                  
            </td>
              </tr>
            </table>
          </form>

这是我的代码:

public static string HttpPostWithCookie(string uri, string parameters, CookieContainer cookieContainer, out string result)
        {
            result = "ok";
            // parameters: name1=value1&name2=value2          
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);
            webRequest.CookieContainer = cookieContainer;
            webRequest.Credentials = CredentialCache.DefaultCredentials;
            webRequest.ContentType = "application/x-www-form-urlencoded";
            webRequest.Method = "POST";
            byte[] bytes = Encoding.ASCII.GetBytes(parameters);
            System.IO.Stream os = null;
            try
            { // send the Post
                webRequest.ContentLength = bytes.Length;   //Count bytes to send
                os = webRequest.GetRequestStream();
                os.Write(bytes, 0, bytes.Length);         //Send it
            }
            catch (WebException ex)
            {
                result = "HttpPost: Request error" + ex.Message;
            }
            finally
            {
                if (os != null)
                {
                    os.Close();
                }
            }

            try
            { // get the response
                WebResponse webResponse = webRequest.GetResponse();
                if (webResponse == null)
                {
                    result = "Empty response";
                    return null;
                }
                System.IO.StreamReader sr = new System.IO.StreamReader(webResponse.GetResponseStream());
                return sr.ReadToEnd().Trim();
            }
            catch (WebException ex)
            {
                result = "HttpPost: Response error" + ex.Message;
            }
            return null;
        } // end HttpPost

不幸的是,我无法发布数据。有没有其他方法可以将数据发布到网页“frog_simple.php”?我收到的只是一个网络响应,上面写着“>>ERROR。没有提交数据”。

4

1 回答 1

0

如果这是您的正文标签内容,我想您的第一个错误是您没有打开表单标签。

于 2012-11-16T10:53:15.043 回答