cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

fetchItemAspects - Downloading and extracting a GZIP file in VB.NET or C#

Just trying to USE fetchItemAspects to download the item specifics for all categories, but I can't seem to collect a useable GZIP file.  Any help would be appreceiated.  Banging my head against a wall at the second.  Thanks.  

 

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim request As HttpWebRequest = WebRequest.Create(ws_URL)
Dim response As HttpWebResponse = Nothing
Dim ws_JsonInfo As String = ""


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' eBay tokens expire after 2 hours and have to be refreshed.
' Putting in a loop here to detect if token expired and to
' refresh it automatically

Dim ws_Success As Boolean = False
Dim ws_ErrorMessage As String = ""
Dim ws_eBayToken As String = strTokenNOTEncrypted
Dim ws_ResultStatus As String = ""

request.Headers.Clear()
request.Accept = "application/json"
'request.ContentType = "application/json"
request.Headers.Add("Accept-Encoding", "gzip")
request.ContentType = "application/gzip"
request.Headers.Add("Content-Encoding", "gzip")

 

request.Method = "GET"
request.Headers.Add("Authorization", "Bearer " & ws_eBayToken)
request.Headers.Add("X-EBAY-API-IAF-TOKEN", ws_eBayToken)
request.Headers.Add("X-EBAY-API-CERT-NAME", strAppKey)
request.Headers.Add("X-EBAY-API-DEV-NAME", strEbayDevName)

 

'We couldn't read the .gz file afterwards
Using reader As IO.Stream = request.GetResponse.GetResponseStream

Using writer As IO.Stream = New IO.FileStream(ws_TestGZIPFileName, IO.FileMode.OpenOrCreate, IO.FileAccess.ReadWrite)
Dim b(1024 * 2) As Byte
Dim buffer As Integer = b.Length
Do While buffer <> 0
buffer = reader.Read(b, 0, b.Length)
writer.Write(b, 0, buffer)
writer.Flush()
Loop
End Using
End Using

 

Message 1 of 3
latest reply
2 REPLIES 2

Re: fetchItemAspects - Downloading and extracting a GZIP file in VB.NET or C#

you need to have Content-Type:application/octet-stream

 

and the X-EBAY headers aren't needed for REST.

 

something like:

Authorization:Bearer TOKEN
Accept:application/json
Content-Type:application/octet-stream
Accept-Encoding:application/gzip

 

See if that helps at all.

 

Message 2 of 3
latest reply

Re: fetchItemAspects - Downloading and extracting a GZIP file in VB.NET or C#

using System;
using System.Net;
using System.IO;
class A
{
  static string iaf = "";
  static void Main()
  {
    byte[] result = null;
    string endpoint = "https://api.ebay.com/commerce/taxonomy/v1/category_tree/0/fetch_item_aspects";
    WebClient client = new WebClient();
    client.Headers.Add("Authorization", $"Bearer {iaf}");
    client.Headers.Add("Accept", "application/json");
    client.Headers.Add("Content-Type", "application/octet-stream");
    result = client.DownloadData(endpoint);
    using (var fs = new FileStream("gzipfileout", FileMode.Create, FileAccess.Write))
    {
        fs.Write(result, 0, result.Length);
    }
  }
}
Message 3 of 3
latest reply