分享

delphi webbrowser post自动登录

 quasiceo 2012-12-27

delphi webbrowser post自动登录  

2011-09-14 10:53:52|  分类: delphi |字号 订阅

var
  EncodedDataString: WideString;
  PostData: OleVariant;
  Headers: OleVariant;
  I: Integer;
begin

  // 创建提交串
  EncodedDataString := 'waybills='+HTTPEncode(edtshippingsn.Text)+'&'+'verifycode=' + HTTPEncode(edtcode.Text);

  // 创建字节方式的可变变量数组,并将字符串转换之。
  PostData := VarArrayCreate([0, Length(EncodedDataString) - 1], varByte);
  // Now, move the Ordinal value of the character into the PostData array
  for I := 1 to Length(EncodedDataString) do
      PostData[I-1] := Ord(EncodedDataString[I]);

  // 头类型
  Headers := 'Content-Type: application/x-www-form-urlencoded' + #10#13;

  // 提交
  wb1.Navigate('http://www./myquery/queryBill.action?locale=zh_CN', EmptyParam,
      EmptyParam, PostData, Headers);

end;

Custom HTTP Header

The only problem is that when the page refreshes the custom header
isn't sent. Anyone run into this?


--- In delphi-webbrowser@yahoogroups.com, "iconinico" <nicowest@h...>
wrote:
> Hi all,
>
> I'm having trouble assigning a custom HTTP header. I've combed the
> web and I can't understand why this doesn't work; on the server the
> header doesn't seem to be there. I use a timer with a 10
millisecond
> delay to get around the problem where frames popup in a new window.
>
> thanks in advance,
>
> NW.
>
>
> var
> tempURL, tempFlags, tempTargetFrameName, tempPostData,
tempHeaders: OleVariant;
> tempBrowser: IWebBrowser2;
> Navigate2Handoff: Boolean;
>
> procedure TForm1.EmbeddedWB1BeforeNavigate2(Sender: TObject;
> const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
> Headers: OleVariant; var Cancel: WordBool);
> begin
> //Navigate2Handoff guards against infinite loops
> If not Navigate2Handoff then begin
> Navigate2Handoff := true;
> Cancel := True; //must cancel here to avoid loops
> tempURL := URL;
> tempFlags := Flags;
> tempTargetFrameName := TargetFrameName;
> tempPostData := PostData;
  //tempHeaders := StringtoVarArray('MyCustom:X'#13#10 + Headers);
tempHeaders := VarArrayToString(Headers) + 'MyCustom:X'#13#10;
> tempBrowser := pDisp as IWebBrowser2;
> Timer1.Enabled := true;
> end;
> end;
>
>
> procedure TForm1.Timer1Timer(Sender: TObject);
> begin
> Timer1.Enabled := false;
> tempBrowser.Navigate2(tempURL, tempFlags, tempTargetFrameName,
> tempPostData, tempHeaders);
> Navigate2Handoff := false;
> end;


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多