저는 HTML 민첩성 팩을 사용하여 http://www.dlapiper.com/global/people/search.aspx?gLastName=A 에있는 변호사 목록을 긁어 모으려고합니다. 사이트는 Ajax를 사용하여 이름을 채 웁니다. 그래서 서버 측에서 행운을 얻지 못했습니다. 사이트에서 웹 서비스를 호출하는 것으로 나타났습니다 ( http://www.dlapiper.com/FCWSite/DlaPiperWS/Attorneys.asmx?op=FindAttorneys). 그래서 내 응용 프로그램에서 동일한 웹 서비스를 호출하려고합니다.
다음 코드를 사용하고 있지만 세션 쿠키가 필요하기 때문에 내부 서버 오류 500이 반환됩니다. (쿠키를 사용하지 않으면 사이트가 작동하지 않으므로)
누구든지 도와 줄 수 있습니까?
private static string WebServiceCall()
{
WebRequest webRequest = WebRequest.Create("http://www.dlapiper.com/FCWSite/DlaPiperWS/Attorneys.asmx?op=FindAttorneys");
HttpWebRequest httpRequest = (HttpWebRequest)webRequest;
httpRequest.Method = "POST";
httpRequest.ContentType = "text/xml; charset=utf-8";
httpRequest.Headers.Add("SOAPAction: http://tempuri.org/");
httpRequest.ProtocolVersion = HttpVersion.Version11;
Stream requestStream = httpRequest.GetRequestStream();
//Create Stream and Complete Request
StreamWriter streamWriter = new StreamWriter(requestStream, Encoding.ASCII);
string request = "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><FindAttorneys xmlns='FCWSite.FCWSite.DlaPiperWS'><scFirstName></scFirstName><scLastName>A</scLastName><scKeyword></scKeyword><scOfficesGUID></scOfficesGUID><scSpokenLanguagesGUID></scSpokenLanguagesGUID><scServicesGUID></scServicesGUID><scRegionGUID></scRegionGUID><scSchoolGUID></scSchoolGUID><scAdmissionGUID></scAdmissionGUID><scLevelGUID></scLevelGUID><strLanguageGUID>7483b893-e478-44a4-8fed-f49aa917d8cf</strLanguageGUID><strCountry>global</strCountry><returnUntranslated>true</returnUntranslated><sortBy>name</sortBy><page>0</page></FindAttorneys></soap:Body></soap:Envelope>";
streamWriter.Write(request);
streamWriter.Close();
//Get the Response
HttpWebResponse wr = (HttpWebResponse)httpRequest.GetResponse();
StreamReader srd = new StreamReader(wr.GetResponseStream());
string resulXmlFromWebService = srd.ReadToEnd();
return resulXmlFromWebService;
}
내 의견에 명시된 바와 같이 .. Attorney.asmx URL을 프로젝트에 웹 참조로 추가했습니다.
그렇게 할 때 웹 참조에 참조의 네임 스페이스가 'com.dlapiper.www'가되도록했습니다.
다음은 vb.net에 있으며 표준 기본 페이지를 나타냅니다. com.dlapiper.www.Attorneys 클래스는 연결 컨텍스트를 나타냅니다.
Attorneys.FindAttorney는 문자열 값을 반환합니다.
또한, 내 버퍼 및 array.convertAll 코드에서 다른 인코딩을 시도했다 볼 수 있습니다. 쿠키 컨테이너 및 다음 쿠키를 추가하지 않고 FindAttorney 호출하려고하면 .. 당신은 잘못 SOAP 예외를 가져올거야 현지화 GUID가 올바른 입력에 없다고 말했습니다.
나는 반 행위 프로그래밍의 팬이기 때문에 코드에서 다소 관련성이없는 부분을 남겨 두었습니다.
사실, 매개 변수는 비워 둘 수 없지만 실제로 함수에서 사용되지는 않습니다. 쿠키 이름 : 값은입니다.
Public Class _Default
Inherits System.Web.UI.Page
Dim AttorneyList As com.dlapiper.www.Attorneys = New com.dlapiper.www.Attorneys()
Dim attys As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim buffer As Byte()
buffer = Array.ConvertAll(Of Char, Byte)("7483b893e47844a48fedf49aa917d8cf".ToUpper.ToCharArray(), New Converter(Of Char, Byte)(AddressOf CharToBuffer))
Dim cookieLanguage As System.Net.Cookie = New System.Net.Cookie
cookieLanguage.Domain = "www.dlapiper.com"
cookieLanguage.Name = "Language"
cookieLanguage.Value = UTF8Encoding.ASCII.GetString(buffer)
cookieLanguage.Path = "/"
Dim cookieLocalization As System.Net.Cookie = New System.Net.Cookie
cookieLocalization.Domain = "www.dlapiper.com"
cookieLocalization.Name = "Localization"
cookieLocalization.Value = "TimeZone=0&UsesDaylightSavings=False&TimeZoneAbbrev=IDLW&Persists=True"
cookieLocalization.Path = "/"
Dim cookieCulture As System.Net.Cookie = New System.Net.Cookie
cookieCulture.Domain = "www.dlapiper.com"
cookieCulture.Name = "DefaultCulture"
cookieCulture.Value = "en-US"
cookieCulture.Path = "/"
Dim cookieHideNotice As System.Net.Cookie = New System.Net.Cookie
cookieHideNotice.Domain = "www.dlapiper.com"
cookieHideNotice.Name = "hide-cookie-notice"
cookieHideNotice.Value = "1"
cookieHideNotice.Path = "/"
Dim cookieMode As System.Net.Cookie = New System.Net.Cookie
cookieMode.Domain = "www.dlapiper.com"
cookieMode.Name = "Mode"
cookieMode.Value = "1"
cookieMode.Path = "/"
Dim cookieNavId As System.Net.Cookie = New System.Net.Cookie
cookieNavId.Domain = "www.dlapiper.com"
cookieNavId.Name = "NavId"
cookieNavId.Value = "1074"
cookieNavId.Path = "/"
Dim cookiePortletId As System.Net.Cookie = New System.Net.Cookie
cookiePortletId.Domain = "www.dlapiper.com"
cookiePortletId.Name = "PortletId"
cookiePortletId.Value = "12601"
cookiePortletId.Path = "/"
Dim cookieSERVER_PORT As System.Net.Cookie = New System.Net.Cookie
cookieSERVER_PORT.Domain = "www.dlapiper.com"
cookieSERVER_PORT.Name = "SERVER_PORT"
cookieSERVER_PORT.Value = "80"
cookieSERVER_PORT.Path = "/"
Dim cookieSiteId As System.Net.Cookie = New System.Net.Cookie
cookieSiteId.Domain = "www.dlapiper.com"
cookieSiteId.Name = "SiteId"
cookieSiteId.Value = "1039"
cookieSiteId.Path = "/"
Dim cookieZoneId As System.Net.Cookie = New System.Net.Cookie
cookieZoneId.Domain = "www.dlapiper.com"
cookieZoneId.Name = "ZoneId"
cookieZoneId.Value = "8"
cookieZoneId.Path = "/"
Dim cookieEventingStatus As System.Net.Cookie = New System.Net.Cookie
cookieEventingStatus.Domain = "www.dlapiper.com"
cookieEventingStatus.Name = "EventingStatus"
cookieEventingStatus.Value = "1"
cookieEventingStatus.Path = "/"
AttorneyList.CookieContainer = New System.Net.CookieContainer()
AttorneyList.CookieContainer.Add(cookieLanguage)
AttorneyList.CookieContainer.Add(cookieLocalization)
AttorneyList.CookieContainer.Add(cookieCulture)
AttorneyList.CookieContainer.Add(cookieMode)
AttorneyList.CookieContainer.Add(cookieEventingStatus)
AttorneyList.CookieContainer.Add(cookieNavId)
AttorneyList.CookieContainer.Add(cookieSiteId)
AttorneyList.CookieContainer.Add(cookieSERVER_PORT)
AttorneyList.CookieContainer.Add(cookieHideNotice)
AttorneyList.CookieContainer.Add(cookiePortletId)
AttorneyList.CookieContainer.Add(cookieZoneId)
'UTF8Encoding.ASCII.GetString(buffer)
attys = AttorneyList.FindAttorneys("B", "", "", "", "", "", "", "", "", "", UTF8Encoding.ASCII.GetString(buffer), "global", False, "name", 0)
Response.Write(attys)
End Sub
Function CharToBuffer(ByVal character As Char) As Byte
Return Convert.ToByte(character)
End Function
End Class