如何发送带有填充值的html表单

Basically i have a html form as string

<form class="form login_form" action="https://app.box.com/api/oauth2/authorize?response_type=code&amp;redirect_uri=http://localhost:8080/&amp;client_id=6n8aeye40bowhwz&amp;state=V8eTbbtXbsV" method="post" name="login_form">
    

      <ul class="container error_container basic_list basic_list_sm hidden"><li class="data plm warning ram pas man"><div class="media pvs"><div class="img icon"><div class="sprite_signup_login_icon_error"></div></div><div class="bd"></div></div></li></ul>

    <div class="field_set login_fields fw center">
        


 <div class="login_user_inputs"><label for="login" class="field_label user_login_field">Email Address</label><div class="user_login_field text_input_with_sprite text_input_with_sprite_16x16 mbm"><input id="login" class="text_input login_email ram field_element " name="login" type="email" title="Email Address" placeholder="Email Address" value="email@gmail.com"> <label class="icon" for="login" title="Email Address"></label></div><label for="password" class="field_label user_password_field">Password</label><div class="user_password_field text_input_with_sprite text_input_with_sprite_16x16 mbm"> <input id="password" class="text_input login_password ram field_element" name="password" title="Password" placeholder="Password" type="password" autocapitalize="off" autocomplete="off" autocorrect="off" value="passwordstring"> <label class="icon" for="password" title="Password"></label></div> </div> <div class="login_submit_div"><input class="btn btn-primary mhn login_submit fw pvm ram" title="Authorize" value="Authorize" type="submit" name="login_submit"></div>   <input type="hidden" name="dologin" value="1" />  <input type="hidden" name="client_id" value="99hxwc5z7wz" /><input type="hidden" name="response_type" value="code" /><input type="hidden" name="redirect_uri" value="http://localhost:8080/" /><input type="hidden" name="scope" value="root_readwrite manage_groups manage_enterprise_properties manage_app_users manage_managed_users" /><input type="hidden" name="folder_id" value="" /><input type="hidden" name="file_id" value="" /> <input type="hidden" name="state" value="Licg8fhDiFyobsV" />  <input type="hidden" name="reg_step" value="" /><input type="hidden" name="submit1" value="1" /><input type="hidden" name="folder" value="" /><input type="hidden" name="login_or_register_mode" value="login" /><input type="hidden" name="new_login_or_register_mode" value="" /><input type="hidden" name="__login" value="1"><input type="hidden" name="redirect_url" value="/api/oauth2/authorize?response_type=code&amp;redirect_uri=http://localhost:8080/&amp;client_id=99hxwc5z7p9g3z&amp;state=LichV8eTbbtXbsV"><input type="hidden" name="request_token" value="5d6b31164f15f58bebff206db0aa595eaa90f5f9b857860f8ac3e64c85a5b5f4">     <input type="hidden" id="_pw_sql" name="_pw_sql" value=""/> 

    </div>
    <div class="sso_switch option_sso mts pvs phm hidden">
        
        <a href='#' class="sso_on" role="button" tabindex="0">Use Single Sign On (SSO)</a>
        
        <a href="#" class="sso_off" tabindex="0">Use Box account credentials</a>
    </div>
</form>

and now i want to submit this form to the url specified in action parameter of form tag. Same as it will be submitted from a browser. And condition is i should not use beego webserver for this. Thanks in advance

</div>

If I understand you correctly, you have to work with an HTML form as opposed to just the input values, and you want to send the input contained in that form to some other server for processing, and you also want to do this programmatically with Go as opposed to clicking on a button inside a browser.

If I got that right, what you have to do is first get the input values, action url, and method from the form. You can do that by using golang.org/x/net/html for example.

After you have all the necessary values you'll have to encode the input values into a valid application/x-www-form-urlencoded string which you can do using the net/url package.

Then all you have to do is to create an http request with http.NewRequest using the form method and action url as it's first two arguments and the urlencoded string as it's last body argument. (You can use strings.NewReader to turn a string into an io.Reader.)

Finally call http.Client.Do on the http.DefaultClient with the newly created request as it's argument.


It's possible that there are some 3rd party packages that do most of this work for you, so if you want to avoid doing this yourself try searching through github.