2012-11-16 56 views
0

我想從內部使用C#控制檯應用程序發佈此表單中的數據。但我不明白爲什麼它不工作。以下是html頁面的body標籤內的表單。在C#控制檯應用程序中將表單數據發佈到服務器

<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」?我所有人都收到了一個web反應,說「>>錯誤。沒有數據提交」。

+0

您可以使用Fiddler準確查看代碼發送的請求,並將其與您在提交表單時瀏覽器發送的內容進行比較。 –

回答

0

如果這是您的身體標記內容,我想您的第一個錯誤是您沒有打開窗體標記。

+0

我不明白你..我已經給了身體內的標籤有形式標籤內容..什麼可能是我的更正..請幫助我詳細..謝謝.. – Sulekha

相關問題