delphi webbrowser post自动登录
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; |
|