I'm starting to add built-in support for StackOver to the OWASP O2 Platform, and just noticed that there is an issue with using the C# API with Fiddler.
It seems that the problem happens when Fiddler is set to 'AutoDecode' the incoming streams.
For reference, here is the script I have so far and the error details (note that I'm using O2's development environment)
- Using this script to search for 'Owasp' in SO via the API:
panel.clear();
var soApi = new API_StackOverflow();
var tagged = new List<string>();
var notTagger = new List<string>();
var sort = "";
var order = "";
return ApiProxy.SearchQuestions("Owasp",tagged,notTagger,sort,order);
//using TheWorldsWorst.ApiWrapper
//O2File:C:\O2\_XRules_Local\API_StackOverflow\API_StackOverflow.cs
- with at the moment consumes just a stub (the extra dll and source references allow me to dynamically compile and consume the C# API)
using TheWorldsWorst.ApiWrapper;
//O2Dir:C:\Documents and Settings\Administrator\My Documents\Downloads\StackOverflow_API\theworldsworststackoverflowclone\TheWorldsWorstApiWrapper
//O2Ref:System.dll
//O2Ref:System.Core.dll
//O2Ref:System.Data.dll
//O2Ref:System.Data.DataSetExtensions.dll
//O2Ref:System.RunTime.Serialization.dll
//O2Ref:System.ServiceModel.Web.dll
//O2Ref:System.Web.dll
//O2Ref:System.Xml.dll
//O2Ref:System.Xml.Linq.dll
namespace O2.XRules.Database.APIs
{
public class API_StackOverflow
{
public ApiProxy SOProxy { get; set; }
public API_StackOverflow() { SOProxy = new ApiProxy(); } } }
- and after making this simple modification in the ApiProxy.cs file so that I get the errors directly in O2:
... inside ApiProxy.cs in method public static string GetUrl(string path)
catch (WebException ex)
{
try
{
ex.log("[SOAPI] in ApiProxy.cs GetUrl"); //send errors to O2
using (var stream = ex.Response.GetResponseStream())
{
var resp = ReadResponse(stream);
var errWrap = ReadObject<Error>(resp);
var err = ReadSingleField(errWrap) as Error;
ErrorCode = err.Code.ToString();
}
}
catch (Exception ex2)
{
ex2.log("[SOAPI] in ApiProxy.cs GetUrl"); //send errors to O2
ErrorCode = "Unknown";
}
}
catch (Exception ex3)
{
ex3.log("[SOAPI] in ApiProxy.cs GetUrl"); //send errors to O2
ErrorCode = "Unknown";
}
- I get the following error (answer is in the final line):
[11:55 AM] ERROR: InnerException: at TheWorldsWorst.ApiWrapper.ApiProxy.GetUrl(String path) in c:\Documents and Settings\Administrator\My Documents\Downloads\StackOverflow_API\theworldsworststackoverflowclone\TheWorldsWorstApiWrapper\ApiProxy.cs:line 128
at TheWorldsWorst.ApiWrapper.ApiProxy.GetObjects[T](String path) in c:\Documents and Settings\Administrator\My Documents\Downloads\StackOverflow_API\theworldsworststackoverflowclone\TheWorldsWorstApiWrapper\ApiProxy.cs:line 174
at TheWorldsWorst.ApiWrapper.ApiProxy.SearchQuestions(String title, IEnumerable1 tagged, IEnumerable1 notTagged, String sort, String order) in c:\Documents and Settings\Administrator\My Documents\Downloads\StackOverflow_API\theworldsworststackoverflowclone\TheWorldsWorstApiWrapper\ApiProxy.cs:line 1159
at DynamicType.dynamicMethod(Object returnData, Panel panel) StackTrace:
at TheWorldsWorst.ApiWrapper.ApiProxy.GetUrl(String path) in c:\Documents and Settings\Administrator\My Documents\Downloads\StackOverflow_API\theworldsworststackoverflowclone\TheWorldsWorstApiWrapper\ApiProxy.cs:line 128
at TheWorldsWorst.ApiWrapper.ApiProxy.GetObjects[T](String path) in c:\Documents and Settings\Administrator\My Documents\Downloads\StackOverflow_API\theworldsworststackoverflowclone\TheWorldsWorstApiWrapper\ApiProxy.cs:line 174
at TheWorldsWorst.ApiWrapper.ApiProxy.SearchQuestions(String title, IEnumerable1 tagged, IEnumerable1 notTagged, String sort, String order) in c:\Documents and Settings\Administrator\My Documents\Downloads\StackOverflow_API\theworldsworststackoverflowclone\TheWorldsWorstApiWrapper\ApiProxy.cs:line 1159
at DynamicType.dynamicMethod(Object returnData, Panel panel)
[11:55 AM] ERROR: InnerException: Unknown Unknown
[11:55 AM] ERROR: in reflection.invokeMethod_InstanceStaticPublicNonPublic Exception has been thrown by the target of an invocation.
[11:55 AM] ERROR: [SOAPI] in ApiProxy.cs GetUrl The magic number in GZip header is not correct. Make sure you are passing in a GZip stream.