My web service client is returning a ? for French characters. My client is calling an axis2/c web service on Apache. I usedwsdl.exe to generate a c# proxy class. When I look at the return in TCPMON, I can see the French characters correctly but in c# they are just showing up as ?. Here is my request and response captured from TCPMON session:
------Request ---
POST /axis2/services/Common HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 4.0.30319.18444)
VsDebuggerCausalityData: uIDPo2iKyNQi9MNOvFI9y0jK6aYAAAAA1bUF2S4JzkGiYsQ0+oayv1AuqfqiggxBj2stf8zH7O4ACQAA
Content-Type: text/xml; charset=utf-8
SOAPAction: ""
Host: localhost:9559
Content-Length: 338
Expect: 100-continue
Connection: Keep-Alive
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><getCriteria xmlns="http://Common.media.jda.com/service"><userId>2285</userId></getCriteria> </soap:Body></soap:Envelope>
----Response ------------
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Date: Wed, 10 Jun 2015 20:36:41 GMT
Server: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8e-fips-rhel5 Axis2C/1.6.0
Content-Length: 2052
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/xml
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body><n:getCriteriaResponse xmlns:n="http://Common.media.jda.com/service"><n:getCriteriaReturn> <n:criteriaId>18219</n:criteriaId><n:criteriaDesc>1415 S PRIMETIMEá</n:criteriaDesc><n:userId>2285</n:userId> <n:seasonCode>1415</n:seasonCode><n:marketType>S</n:marketType><n:networkCode>P</n:networkCode><n:networkDaypartId>0</n:networkDaypartId><n:salesTypeId>0</n:salesTypeId><n:advId>0</n:advId><n:agencyId>0</n:agencyId><n:acctExecId>0</n:acctExecId><n:plannerId>0</n:plannerId><n:defaultInd>false</n:defaultInd></n:getCriteriaReturn><n:getCriteriaReturn><n:criteriaId>18972</n:criteriaId><n:criteriaDesc>1415 U Daytimeá</n:criteriaDesc><n:userId>2285</n:userId><n:seasonCode>1415</n:seasonCode><n:marketType>U</n:marketType><n:networkCode>M</n:networkCode><n:networkDaypartId>0</n:networkDaypartId><n:salesTypeId>0</n:salesTypeId><n:advId>0</n:advId><n:agencyId>0</n:agencyId><n:acctExecId>0</n:acctExecId><n:plannerId>0</n:plannerId><n:defaultInd>false</n:defaultInd></n:getCriteriaReturn><n:getCriteriaReturn><n:criteriaId>18221</n:criteriaId><n:criteriaDesc>1415 U PRIMETIMEá</n:criteriaDesc><n:userId>2285</n:userId><n:seasonCode>1415</n:seasonCode><n:marketType>U</n:marketType><n:networkCode>P</n:networkCode><n:networkDaypartId>0</n:networkDaypartId><n:salesTypeId>0</n:salesTypeId><n:advId>0</n:advId><n:agencyId>0</n:agencyId><n:acctExecId>0</n:acctExecId><n:plannerId>0</n:plannerId><n:defaultInd>false</n:defaultInd></n:getCriteriaReturn><n:getCriteriaReturn><n:criteriaId>18284</n:criteriaId><n:criteriaDesc>1516 DADT Upfrontá</n:criteriaDesc><n:userId>2285</n:userId><n:seasonCode>1516</n:seasonCode><n:marketType>U</n:marketType><n:networkCode>I</n:networkCode><n:networkDaypartId>0</n:networkDaypartId><n:salesTypeId>0</n:salesTypeId><n:advId>0</n:advId><n:agencyId>0</n:agencyId><n:acctExecId>0</n:acctExecId><n:plannerId>0</n:plannerId><n:defaultInd>false</n:defaultInd></n:getCriteriaReturn></n:getCriteriaResponse> </soapenv:Body></soapenv:Envelope>
Any help would be greatly appreciated. Here is my function in the proxy class generated by wsdl.exe:
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("", RequestNamespace="http://Common.media.jda.com/service", ResponseNamespace="http://Common.media.jda.com/service", Use=System.Web.Services.Description.SoapBindingUse.Default, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[return: System.Xml.Serialization.XmlElementAttribute("getCriteriaReturn")]
public CriteriaRec[] getCriteria(int userId) {
object[] results = this.Invoke("getCriteria", new object[] {
userId});
return ((CriteriaRec[])(results[0]));
}
I was able to resolve this issue by creating and override function:
protected override WebResponse GetWebResponse(WebRequest request)
{
WebResponse webResponse = base.GetWebResponse(request);
webResponse.Headers["Content-Type"] = "text/xml; charset=iso-8859-15";
return webResponse;
}
This works fine. In addition, I specified the requestEncoding to take care of sending data back:
myservice.RequestEncoding = System.Text.Encoding.GetEncoding("iso-8859-15");
Related
When trying to execute a request using Microsoft.Office365.OutlookServices OutlookServicesClent with query, returns with Microsoft.OData.Client.DataServiceQueryException
Stack trace:
at Microsoft.OData.Client.DataServiceContext.InnerSynchExecute[TElement](Uri requestUri, String httpMethod, Nullable1 singleResult, OperationParameter[] operationParameters)
at Microsoft.OData.Client.DataServiceRequest.Execute[TElement](DataServiceContext context, QueryComponents queryComponents)
at Microsoft.OData.Client.DataServiceContext.Execute[TElement](Uri requestUri, String httpMethod, OperationParameter[] operationParameters)
at BL.OutlookAnalysisService.GetListOfMessagesByQuery(OutlookServicesClient service, Uri searchUri
and the error is:
Microsoft.OData.Client.DataServiceQueryException)exception).Response.Error"{\"error\":{\"code\":\"ErrorServiceUnavailable\",\"message\":\"Active Directory operation did not succeed. Try again later.\"}}"
System.Exception {Microsoft.OData.Client.DataServiceClientException}
Update
http request:
`GET /api/v2.0/me/mailfolders/SentItems/messages?$filter=ReceivedDateTime%20ge%202016-11-22 HTTP/1.1
OData-MaxVersion: 4.0
Accept: application/json;odata.metadata=minimal
Accept-Charset: UTF-8
User-Agent: Microsoft ADO.NET Data Services
Authorization: Bearer EwAYA+l3BAAUWm1xSeJRIJK6txKjBez4GzapzqMAAfh6O0QoQEsdN6OkFbuNKi/TXNzqUKWObaTUhPeziD3SYgEvHNGDxcvME0+Tt0/L8pWBlOSkeaKEYgd3B7C7go+8pDVQGeBoHhLhrmp4zMbtbdOiDJcxRwaUJ36Ak4DpCV665COyP2tS5/zbbq9+EIBFg0TQWbdOjMqN12DJGvRR+TzgMwWDV3IE1sJzAOi5CzYM7oy1pS1JX7JBq8ZxB7+kI1tjksanXymLZ5mlRRJp+XoR73mBocIgljLRPFaovyzUzMsEuTAvZ1gbbYqqH0u+hXNrlDDsFKtKeXb8IWGYeud+WMGmZbatt4LTZTXmBFYJf9hYZdaKNBQkBbvnc4IDZgAACHKN9ak8g6O86AHAhJwa9lFr9IgY4SPRdmUHqYDC4TSr8R+RVsANy4RSFe/p90sdRZXwvFsQ4JioWsVtQ0J3Aoh9cVNOKgZg2SIqm2Ni8VHD/EXSqtZqu0KZCKFSRrRxUSdzr3oG98hhbo1DcykWWyiI9PuPBxkFT60ZjC8+1NyXiX64vDOAQ9jvNf4BpGiahfDuzWajmeDiPXMd25ohXeY6s4XX5XhWDWXrDA5CdU+n1ZyF4kzUtCvalWTCIqRQ0UOXmEqa1nWNFIC0Vb6gTZl3HJqkRZxY9X+V0qHJYZyr5Ynss+FajWxnoYqasNNGZDWlJmBeAlIcWHO4kd8ggBiBBZdl7+unO1+jJhenRV2sSFGx11DQPOzRC3DvqwMwr0iJ9ZJ6vMUrAmvT1M3+0fyXEJsvfnz043oSgjPnQbihmtvlqIKO4M3kp3uKaRU2XOGhID9nsS31YefVDgThBzGLstRmj7jaMVbUQKkIZ0WYWIdp9uHEYWHlq0bvyvBqULmQMXAXczOuYaKAfOZqZX+FDaBYF6+BkGVtJ233sd7NwM8kInYnbLgtjAgyS9lxcqCCR2Kax6yhwBRFtNbV1F9+w4CC7K+EDelp8KGQUEA65MLwkZaO28rjagU3ps+uiAVr+IhsBO4XUVmCBpjIO6y1SxYC
X-ClientService-ClientTag: Office 365 API Tools 1.0.33.0
X-AnchorMailbox: outlook_F26A78076F4A0070#outlook.com
Host: outlook.office.com`
http response:
`HTTP/1.1 503 Service Unavailable
Content-Length: 0
Server: Microsoft-IIS/8.5
request-id: f1eec46a-9e69-426e-8013-a321b32b6916
X-CalculatedFETarget: namprd07-provisioning.internal.outlook.com
X-ProxyErrorLabel: ProxyHandler::OnWinHttpRequestError/WinHttpRequest::ReceiveResponse
X-ProxyErrorHResult: 0x80072efe
X-ProxyErrorMessage: The connection with the server was terminated abnormally
X-Powered-By: ASP.NET
X-FEServer: BLUPR14CA0027
X-MSEdge-Ref: Ref A: F0C2366F72364B08A9C270672FB271C1 Ref B: 1C1593F5E64AF33E0BE980EA9B1B6CDD Ref C: Thu Dec 22 00:30:31 2016 PST
Date: Thu, 22 Dec 2016 08:30:30 GMT`
Update 2
After some investigation, turns out that we are using this code:
var dataProvider = new MicrosoftProviderAdapter(new Uri("https://outlook.office.com/api/v2.0"), GetAccessToken);
var userDetail = await dataProvider.Me.ExecuteAsync();
dataProvider.Context.SendingRequest2 +=(sender,e)=>InsertXAnchorMailboxHeader(sender, e, userDetail.EmailAddress);`
to insert X-AnchorMailbox but for some reason if logged in with sheta.fadi#outlook.com the response
of await dataProvider.Me.ExecuteAsync() has outlook_F26A78076F4A0070#outlook.com as email and not sheta.fadi#outlook.com
p.s. this call worked up until last week
I would like to get the response of a json api provided by some website this is their cURL Request
curl --include --header "X-Access-Token: XXXXX" "http://api.travelpayouts.com/v2/prices/latest?"
trying to get the content using
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("X-Access-Token", "XXXXX");
HttpResponseMessage response = await client.GetAsync(url);
var contents = await response.Content.ReadAsStringAsync();
MessageBox.Show(contents);
}
but still getting
{"success":false,"data":null,"message":"Unauthorized"}
Are you sure that you are using token? in your code it looks like a marker.
Here is my output:
#e:~$ curl --include --header "X-Access-Token: d273e9325fXXXXXXXXXXXXX" "http://api.travelpayouts.com/v2/prices/latest?currency=rub&period_type=year&page=1&limit=30&show_to_affiliates=true&sorting=price&trip_class=0"
HTTP/1.1 200 OK
Server: nginx/1.2.4
Date: Wed, 25 Nov 2015 13:53:52 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 7083
Connection: keep-alive
Vary: Accept-Encoding
Status: 200 OK
X-Content-Type-Options: nosniff
{"success": true, "data":
I am trying to sending a POST to a java web-service with my windows phone app using this c# code:
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(new
MediaTypeWithQualityHeaderValue("application/json"));
var requestContent = new StringContent(json);
requestContent.Headers.ContentType = new
MediaTypeWithQualityHeaderValue("application/json");
var response = await client.PostAsync(requestUri, requestContent);
//...
}
but I am getting a 400 Bad Request and sending this header:
POST [myreq] HTTP/1.1
Content-Type: application/json
Content-Length: 340
Accept-Encoding: identity
Accept: application/json
User-Agent: NativeHost
Host: [myhost]
Connection: Keep-Alive
Pragma: no-cache
and the only difference that I see from a valid similar (to the same web service) android java request is this line in my header:
access-control-allow-methods=[POST]
How to include this access-control-allow-methods with C#?
for future help
client.DefaultRequestHeaders.Add("Access-Control-Allow-Methods", "POST");
I am attempting to set up Log In With Paypal, but I am receiving a Unauthorized Message ("{\"error_description\":\"Unable to generate token\",\"error\":\"access_denied\"}") while obtaining the access token ( I received the authorization code without a hiccup). The only thing I think I might have wrong is the availability of this service to non US residents. It says that REST APIs is not available to non US residents, but I noticed that its segregated from the 'Log In With Paypal'. Does anyone know?
Here is the code I am using too retrieve the access token in case anyone can notice an error:
string TokenEndpoint = "https://api.paypal.com/v1/identity/openidconnect/tokenservice";
System.Collections.Specialized.NameValueCollection reqparm = new System.Collections.Specialized.NameValueCollection();
reqparm.Add("client_id", this._clientId);
reqparm.Add("client_secret", this._clientSecret);
reqparm.Add("grant_type", "authorization_code");
reqparm.Add("code", authorizationCode);
reqparm.Add("redirect_uri", HttpUtility.UrlEncode(returnUrl.AbsoluteUri));
try
{
using (WebClient client = new WebClient())
{
var data = client.UploadValues(TokenEndpoint, "POST", reqparm); // Access Denied exception occurs here.
...
Here is the response I receive:
HEADER
{
Pragma: no-cache
Vary: Accept-Encoding
Connection: close
Content-Length: 72
Cache-Control: no-store
Content-Type: application/json
Date: Mon, 10 Jun 2013 23:35:02 GMT
Server: Apache-Coyote/1.1
}
Content
text
{
\"error_description\":\"Unable to generate token\",
\"error\":\"access_denied\"
}"
I'm using HttpWebRequest component and trying to POST data to server.
When I use browser I can trace that it sends this request
POST https://plus.google.com/_/socialgraph/mutate/modifymemberships/?_reqid=1950158&rt=j HTTP/1.1
Host: plus.google.com
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:8.0.1) Gecko/20100101 Firefox/8.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection: keep-alive
X-Same-Domain: 1
Content-Type: application/x-www-form-urlencoded;charset=utf-8
Referer: https://plus.google.com/_/apps-static/_/js/home/b,s/rt=h/ver=OeD97kiQfn8.en./sv=1/am=!iPoVWvyH1UcKPT9bc1pNSZLcSj8oHAelto24gJorhwk/d=1/
Content-Length: 216
Cookie: PREF=ID=c42cff62752fc3e8:U=dae37ffa177e0689:FF=0:TB=2:LD=en:CR=2:TM=1244434765:LM=1311323210:DV=0SJoub_nzRUL:GM=1:S=EuE8opfqNl8PGGHI; NID=54=enDovqVn7CSHrPtZ2ZSPAt4PrE0ZZE-rWJawva2NiUWC1TzreG-sVdiSnRp7kolqcvMCGCIKt7agHKT6Hi2JZkV5qYmY_fUkxFjk6PUc7TrdNRAT7_9mRnvwOxeBOcng; rememberme=false; __utma=1.340991765.1324442547.1324723420.1324806933.8; __utmz=1.1324723420.7.7.utmcsr=google.com|utmccn=(referral)|utmcmd=referral|utmcct=/accounts/Logout2; OTZ=1044056_4_4_133320_8_385320; S=analytics-realtime-frontend=h23QCGj_I9O7FLG9cqDjkA:awfe=SnIt_U1wxuihQ1myCwuiZA:awfe-efe=lCXLSEuiUzX3HyaRuXVuRg:adwords-optimization=yCZeLrx1FD0uGQFYb07LTQ:adwords-common-ui=WfNukVX7rVpTuVtMlZ6IbA; S_awfe=tyb6VRVQyBHkv8nbfMNWRg; GMAIL_RTT=571; __utmc=1; HSID=AtaMO-oLk9-OMZkiv; SSID=AGt3gDSdd3Q98pA81; APISID=7xRgosYs7uOXzd0Y/AI4OXaHRTViR8oE8s; SAPISID=0HNI_ffNupNL-UfT/Ao6YbG5vkEashPdOM; ULS=EgYKBBICZW4Yy-Xb9wQ; SID=DQAAALMAAADk5OelxcPoQKO8FrSoOfOGoTHX4HeVfeJJQhtd19k07mJMUhJkiehF1FTzb7jNt34c80UGpyXEJT5FML373p6RR_5EQ3etVYjUXmgqHsdO7G-XuP_k_m798MDvd4AWkDX2vKVtqc5zA_olxB9UkJBLU_g2IM2vZ3Scp-eThZj8C3uZuzdN_DCpQeVjrU6a1kiIdQRsz9rUtxzoC0E22Ux4ba0QneaWBT73Ns14wh7fqZtYB-DRB2zcWkXXoNnV67U; FBS_VI_1324806859_0=ot_00Qg-hkQV7uhIEb0dTMT0_DD6aAI
Pragma: no-cache
Cache-Control: no-cache
a=%5B%5B%5B%225947b6d78a8231f3%22%5D%5D%5D&m=%5B%5B%5B%5Bnull%2Cnull%2C%22113690702042497323038%22%5D%2C%22Stephanie%20Parker%22%2C%5B%5D%5D%5D%5D&r=%5B%5B%5D%5D&at=AObGSAg06IXl5iYSceecKRc64xHVAB_GDw%3A1324806859000&
And when I use HttpWebRequester is sends following data which results in Code 400 rather then Code 200
POST https://plus.google.com/_/socialgraph/mutate/modifymemberships/?_reqid=1950158&rt=j HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:8.0.1) Gecko/20100101 Firefox/8.0.1
Accept-Language: en-gb,en;q=0.5
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
X-Same-Domain: 1
Content-Type: application/x-www-form-urlencoded;charset=utf-8
Referer: https://plus.google.com/_/apps-static/_/js/home/b,s/rt=h/ver=OeD97kiQfn8.en./sv=1/am=!iPoVWvyH1UcKPT9bc1pNSZLcSj8oHAelto24gJorhwk/d=1/
Pragma: no-cache
Cache-Control: no-cache
Host: plus.google.com
Cookie: ULS=EgYKBBICZW4Yp_7k9wQ; SID=DQAAALYAAAAZuUVe6hDQbW__dA1Itrcz8thm2Ncxk5YFMfpeiKyr6Pps1Pu0ajmReczMDHKGnDpk3yrx7WFy-5QMOf0Fu4WiPVdUWcU_cLNfD7FhKtqmSmOgFiffTkyj8dg0bsTeahhrKR7j75rjU_eXqGnQI2qcJHOyk1cLEkWNaWyLRGeYDrsfAh6uzx4AI-1GtKbwwrE7UHsn_sUFG1DuwI_Ct_g9C2llFVVyQruvFnlmRE1xDE_ORwvnBYCrGQYjyt1blg8; HSID=AbkExs5EzrPodpoKx; SSID=A2y_-xD7iOhW9Y2HF; APISID=73YQ7BugDgjmMSdd/AgFF1ClZc0z-fpPGM; SAPISID=mT6qzvCACzlvDrg-/AN1ajSgZCB0R9xOmX
Content-Length: 216
Connection: Keep-Alive
a=%5b%5b%5b%225947b6d78a8231f3%22%5d%5d%5d&m=%5b%5b%5b%5bnull%2cnull%2c%22113690702042497323038%22%5d%2c%22Stephanie%20Parker%22%2c%5b%5d%5d%5d%5d&r=%5b%5b%5d%5d&at=AObGSAg06IXl5iYSceecKRc64xHVAB_GDw%3a1324806859000&
So any idea why this to similar requests have 2 different server response?
BTW I did check cookies and they are fine. I'm just puzzled on why my request would not work.
UPDATE Request Code added
webRequest_ = (HttpWebRequest)HttpWebRequest.Create(Params.URL);
webRequest_.Method = "POST";
//webRequest_.Proxy = new WebProxy("http://plus.google.com", false);
webRequest_.UserAgent = Params.UserAgent;
webRequest_.Headers.Add("Accept-Language", "en-gb,en;q=0.5");
webRequest_.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
webRequest_.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
webRequest_.KeepAlive = true;
webRequest_.Headers.Add("X-Same-Domain", "1");
webRequest_.ContentType = "application/x-www-form-urlencoded;charset=utf-8";
webRequest_.Referer = "https://plus.google.com/_/apps-static/_/js/home/b,s/rt=h/ver=OeD97kiQfn8.en./sv=1/am=!iPoVWvyH1UcKPT9bc1pNSZLcSj8oHAelto24gJorhwk/d=1/";
webRequest_.CookieContainer = Params.Cookie;
webRequest_.Headers.Add("Pragma", "no-cache");
webRequest_.Headers.Add("Cache-Control", "no-cache");
var sp = webRequest_.ServicePoint;
var prop = sp.GetType().GetProperty("HttpBehaviour", BindingFlags.Instance | BindingFlags.NonPublic);
prop.SetValue(sp, (byte)0, null);
var parameters = new StringBuilder();
foreach (var key in Params.Params)
{
parameters.AppendFormat("{0}={1}&", HttpUtility.UrlEncode(key.ToString()),
HttpUtility.UrlEncode(Params.Params[key.ToString()]).Replace("+","%20"));
}
using (var writer = new StreamWriter(webRequest_.GetRequestStream()))
{
writer.Write(parameters.ToString());
}
After extensive testing I have figured out that problem is not in a header but rather in the data that gets posted, particularly in "at" parameter which is stands for session Id. After successfully generation session id it did work like a charm.