我需要将"HTTP Post"与WebClient一起使用,将一些数据发布到特定的URL。我在将值传递给输入类型"无线电"时遇到一些问题。
部分网页代码:
<li class='cua_cols'>NIF a seleccionar<br />
<big><strong>A********</strong></big>
</li>
<li><label for='wNif'><input type='hidden' id='wNif' name='wNif' value='A********' /></label></li>
<li class='dos_cols'>
<label for='TIPONIF0'>
que actúa como
<br />
</label>
<b>Operador </b><input type='radio' id='TIPONIF0' name='TIPONIF' value='OP' checked = 'checked' />
<b>Autorizado </b><input type='radio' id='TIPONIF1' name='TIPONIF' value='AU' />
</li>
<li class='ancho_99'> </li><li class='cua_cols'>
<label for='wNifAut'>
NIF relacionado=
<br />
<input type='text' name='wNifAut' id='wNifAut' value='B********' maxlength='17' size='19' onkeypress='javascript:if (event.keyCode == 13) return false; ' onclick='' />
</label></li>
<li class='cua_cols'>
<label for='TIPONIF_SOL0'>
que actúa como
<br />
</label>
<b>Operador </b><input type='radio' id='TIPONIF_SOL0' name='TIPONIF_SOL' value='OP' />
<b>Autorizado </b><input type='radio' id='TIPONIF_SOL1' name='TIPONIF_SOL' value='AU' checked = 'checked' />
</li>
在第一次,下一个代码工作正常,但今天只分配wNifAut值。
Dim requestData As New NameValueCollection()
requestData.Add("wNifAut", mnoCIF)
requestData.Add("TIPONIF1", "true")
requestData.Add("TIPONIF_SOL0", "true")
requestData.Add("Buscar", "Click")
Dim request As Byte() = myWebClient.UploadValues(msStrURL, "POST", requestData)
msHTMLString = Encoding.UTF8.GetString(request)
OP 的解决方案。
页面的源代码也包含以下内容:
<label for="VEZ"><input name="VEZ" id="VEZ" type="hidden" value=""></label>
<div class="AEAT_bloque_botones">
<input name="Buscar" class="AEAT_boton" accesskey="A" onkeypress='javascript:enviarDatos("BUSCAR1");' onclick='javascript:enviarDatos("BUSCAR1");' type="button" value="Buscar">
<input name="Limpiar" class="AEAT_boton" accesskey="D" onkeypress='javascript:resetear(getVarDom("Query"));' onclick='javascript:resetear(getVarDom("Query"));' type="button" value="Limpiar">
</div>
<script type="text/javascript">
function enviarDatos(opcion) { getVarDom("Query").VEZ.value=opcion;
getVarDom("Query").submit(); }
</script>
我更改了代码中的一些行:
Dim requestData As New NameValueCollection()
requestData.Add("wNif", mnoCIFComp)
requestData.Add("wNifAut", mnoCIF)
requestData.Add("TIPONIF", "AU")
requestData.Add("TIPONIF_SOL", "OP")
requestData.Add("VEZ", "BUSCAR1")
Dim request As Byte() = myWebClient.UploadValues(msStrURL, "POST", requestData)
msHTMLString = Encoding.UTF8.GetString(request)
重要变化
1) I indicated the input radio values with pair (name - value) instead of (id - 'true')
2) I assigned the value "BUSCAR1" to the hidden label, to simulated the JavaScript function.
3) In this case I had to assign the company cif.