简体   繁体   English

无法找出正确的参数来模仿Java中的网站表单

[英]Can't figure out the correct Parameter to mimic a website form in Java

I'm a beginner with website source code and Java, I'm trying to figure out a way to access a certain site programmatically. 我是网站源代码和Java的初学者,我试图找到一种以编程方式访问特定网站的方法。 I figured out the login/authentication part, but now I'm stuck at something that should be fairly easy. 我知道了登录/身份验证部分,但现在我陷入了应该相当容易的事情。 I need to tell Java to select from a list of options, but I can't figure out what parameters to send for the following source code: 我需要告诉Java从选项列表中进行选择,但是我不知道要为以下源代码发送哪些参数:

<FORM ACTION="/services/reinforce" METHOD="POST" onSubmit="return checkSubmit()">
<INPUT TYPE="hidden" NAME="call1" VALUE="search">
<TABLE  CLASS="Data_table" summary="Select an option"width="100%"><CAPTION class="ctext">Search:    </CAPTION>
<TR>
<TD CLASS="default"><LABEL for=input_id><SPAN class=fvisible>Options</SPAN></LABEL>
<SELECT NAME="val_num" SIZE="1"  ID="optionId">
<OPTION VALUE="">None
<OPTION VALUE="1">Option 1
<OPTION VALUE="2">Option 2
<OPTION VALUE="3">Option 3
<OPTION VALUE="4">Option 4
<OPTION VALUE="5">Option 5
<OPTION VALUE="6">Option 6
<OPTION VALUE="7">Option 7
...

For instance if I want to select option 1, what I usually do is 例如,如果我想选择选项1,我通常要做的是

String data = URLEncoder.encode("val_num", "UTF-8") + "=" + URLEncoder.encode("1", "UTF-8"); 

Somehow it is working, its NOT returning a FileNotFoundException, but it's redirecting me to another link. 它以某种方式工作,它没有返回FileNotFoundException,但是将我重定向到另一个链接。 When I do it manually in any browser it works fine and it redirects me to Option1. 当我在任何浏览器中手动进行操作时,它都可以正常工作,并将我重定向到Option1。 What might be wrong? 可能有什么问题?

Are you also sending in the parameter corresponding to hidden input element. 您是否也在发送与隐藏的输入元素相对应的参数。

String data = "call1=search&val_num=1";

(Note there is no need to URL-encode when you can see clearly that the string only contains URL-safe characters.) (请注意,当您可以清楚地看到字符串仅包含URL安全字符时,就无需进行URL编码。)

Also I assuming you are passing this data string to POST request (not a GET request). 另外,我假设您正在将此数据字符串传递给POST请求(而不是GET请求)。 Is that correct? 那是对的吗?

Here is a check list: 以下是检查清单:

  1. Are you making a POST request to /services/reinforce ? 您是否要向/services/reinforce发出POST请求?
  2. Does the checkSubmit() JavaScript function make any changes to the form's input/select/textarea elements before the form is submitted? 在提交表单之前, checkSubmit() JavaScript函数是否checkSubmit()表单的输入/选择/文本区域元素进行任何更改? If so, you need to simulate those changes in the data that you send with the POST request. 如果是这样,则需要模拟通过POST请求发送的数据中的那些更改。 (It may help to edit your question and add the source of the checkSubmit() function.) (这可能有助于编辑您的问题并添加checkSubmit()函数的源。)
  3. Are you setting the request content type to application/x-www-form-urlencoded ? 您是否将请求内容类型设置为application/x-www-form-urlencoded
  4. Are you sending the appropriate authorization? 您是否正在发送适当的授权? Usually web sites send a cookie upon successful authentication. 通常,网站在身份验证成功后会发送cookie。 Are you sending the correct Cookie header? 您是否发送了正确的Cookie标头?
  5. Is data the content body of the POST request? data是POST请求的内容主体吗?
  6. Have you tried sending call1=search in the body as well? 您是否也尝试过在体内发送call1=search Perhaps the hidden field is also necessary. 也许隐藏的领域也是必要的。
  7. What User-Agent header are you sending? 您要发送什么User-Agent标头?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM