2016-11-17 9 views
1

APIにキーフレーズのためにドキュメントを送信すると、返されたJSONレスポンスに「リクエスト内のドキュメントが処理するには大きすぎます。ドキュメントサイズを10240バイトに制限します"Microsoft Cognitive APIドキュメントのサイズ制限10240バイト

https://docs.microsoft.com/en-us/azure/cognitive-services/cognitive-services-text-analytics-quick-startによれば、「提出できる文書の最大サイズは10KBで、提出された入力の最大サイズは1MBです.1回の呼び出しで1,000件を超える文書を提出することはできません。

問題の文書はEncoding.UTF8.GetBytesを使用して、バイト長(長7713.の文字列です)に提出された7763.

全体のByteArrayの長さの7965.

小さめの文字列です問題はありませんが、長さ3000を超える文字列にはこの問題があるようです。

' Create a JSONInput object containing the data to submit 
    Dim myJsonObject As New JSONInput 
    Dim input1 As New JSONText 
    input1.id = "1" 
    input1.text = text 
    myJsonObject.documents.Add(input1) 

    ' Translate the JSONInput object to a serialized JSON string 
    Dim jss As New JavaScriptSerializer() 
    Dim jsonString As String = jss.Serialize(myJsonObject) 

    ' Windows Cognitive Services URL 
    Dim request As System.Net.WebRequest = System.Net.WebRequest.Create("https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/keyPhrases") 

    ' Set the Method property of the request to POST. 
    request.Method = "POST" 

    ' Add a header with the account key. 
    request.Headers.Add("Ocp-Apim-Subscription-Key", accountKey_TextAnalytics) 

    ' Create POST data and convert it to a byte array. 
    Dim postData As String = jsonString 
    Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData) 

    ' Set the ContentType property of the WebRequest. 
    request.ContentType = "application/json" 

    ' Set the ContentLength property of the WebRequest. 
    request.ContentLength = byteArray.Length 

    ' Get the request stream. 
    Dim dataStream As System.IO.Stream = request.GetRequestStream() 

    ' Write the data to the request stream. 
    dataStream.Write(byteArray, 0, byteArray.Length) 

    ' Close the Stream object. 
    dataStream.Close() 

    ' Get the response. 
    Dim response As System.Net.WebResponse = request.GetResponse() 

    ' Get the stream containing content returned by the server. 
    dataStream = response.GetResponseStream() 

    ' Open the stream using a StreamReader for easy access. 
    Dim reader As New System.IO.StreamReader(dataStream) 

    ' Read the content. 
    Dim responseFromServer As String = reader.ReadToEnd() 

    ' Display the content. 
    Console.WriteLine(responseFromServer) 

    ' Clean up the streams. 
    reader.Close() 
    dataStream.Close() 
    response.Close() 

    ' Deserialize the json data 
    jss = New JavaScriptSerializer() 
    Dim jsonData = jss.Deserialize(Of Object)(responseFromServer) 

    ' List of key phrases to be returned 
    Dim phrases As New List(Of String) 
    For Each item As String In jsonData("documents")(0)("keyPhrases") 
     phrases.Add(item) 
    Next 

    Return phrases 

私の質問があり、私はここで間違っているかもしれないもの、私はそれを私の文書は10240バイトのサイズ制限を超えているメッセージを受信し、しかしだことを、下記VB.NETで書かれたコードは、あります私がPOSTしたデータがその限界を十分に下回っているようです。

+0

あなたの質問は... –

+0

httpリクエストでエンコーディングヘッダーを指定していないのがわかります。 UTF-8を指定しようとしましたか? –

答えて

0

上記のように、UTF-8エンコーディングを指定してください。

関連する問題