簡體   English   中英

Z39.50來自服務器的不可讀響應

[英]Z39.50 Unreadable Response From Server

我正在使用C#,Visual Studio 2010和Zoom.net創建一個客戶端來從Z39.50服務器獲取數據,但是我得到了一個不可讀的響應。

我注意到響應中包含的數字就像這個響應一樣,但每行的內容在某些地方都是不可讀的。 我想這個問題只適用於用英語以外的語言編寫的單詞,這些特定單詞的結果是數字或奇怪的符號。 這是一個帶有字節數組響應的文件

此屏幕截圖是對我的客戶的回復。

在此輸入圖像描述

這是我的代碼:

class Program
{
    static void Main(string[] args)
    {
        try
        {
            using (var con = new Connection("url", port))
            {
                con.DatabaseName = "<name here>";
                con.Syntax = Zoom.Net.RecordSyntax.GRS1;

                var query = "@attr 1=21 @attr 2=3 @attr 3=3 @attr 4=2 " + 
                            "@attr 5=100 @attr 6=1 \"John\""; 
                var results = con.Search(q);

                for (uint i = 0; i < results.Size; i++)
                {
                     string temp = Encoding.UTF8.GetString(results[i].Content);
                }
            }
        }
        catch(Exception exc)
        {
            Console.WriteLine(exc.Message);
            Console.Read();
        }
    }
}

問題解決了,我使用下面的自定義類為希臘字符utf8編碼。

namespace MARC
{
    public class advancedGreekClass
    {
        protected byte[] inp;
        protected int pos;

        public advancedGreekClass(byte[] data)
        {
            inp = data;
            pos = 0;
        }

        public string GetString()
        {
            var sb = new StringBuilder(1000000);
            ulong ch;
            for (; ; ) {
                ch = read_advancegreek();
                if (ch == 0) break;
                sb.Append((char)ch);
            }
            return sb.ToString();
        }

        private ulong read_advancegreek()
        {
            int byteArraySize = inp.Length - pos;
            ulong x = 0;
            bool shift = false;
            bool tonos = false;
            bool dialitika = false;

            while (byteArraySize > 0)
            {
                if (inp[pos] == 0x9d) //inp[i]
                {
                    tonos = true;
                }
                else if (inp[pos] == 0x9e)
                {
                    dialitika = true;
                }
                else if (inp[pos] == 0x9f)
                {
                    shift = true;
                }
                else
                    break;

                --byteArraySize;
                pos++;
            }

            if (byteArraySize == 0)
            {
                return 0;
            }

            switch (inp[pos])
            {
                case 0x81:
                    if (shift)
                        if (tonos)
                            x = 0x0386;
                        else
                            x = 0x0391;
                    else
                        if (tonos)
                            x = 0x03ac;
                        else
                            x = 0x03b1;
                    break;
                case 0x82:
                    if (shift)
                        x = 0x0392;
                    else
                        x = 0x03b2;

                    break;
                case 0x83:
                    if (shift)
                        x = 0x0393;
                    else
                        x = 0x03b3;
                    break;
                case 0x84:
                    if (shift)
                        x = 0x0394;
                    else
                        x = 0x03b4;
                    break;
                case 0x85:
                    if (shift)
                        if (tonos)
                            x = 0x0388;
                        else
                            x = 0x0395;
                    else
                        if (tonos)
                            x = 0x03ad;
                        else
                            x = 0x03b5;
                    break;
                case 0x86:
                    if (shift)
                        x = 0x0396;
                    else
                        x = 0x03b6;
                    break;
                case 0x87:
                    if (shift)
                        if (tonos)
                            x = 0x0389;
                        else
                            x = 0x0397;
                    else
                        if (tonos)
                            x = 0x03ae;
                        else
                            x = 0x03b7;
                    break;
                case 0x88:
                    if (shift)
                        x = 0x0398;
                    else
                        x = 0x03b8;
                    break;
                case 0x89:
                    if (shift)
                        if (tonos)
                            x = 0x038a;
                        else
                            if (dialitika)
                                x = 0x03aa;
                            else
                                x = 0x0399;
                    else
                        if (tonos)
                            if (dialitika)
                                x = 0x0390;
                            else
                                x = 0x03af;

                        else
                            if (dialitika)
                                x = 0x03ca;
                            else
                                x = 0x03b9;
                    break;
                case 0x8a:
                    if (shift)
                        x = 0x039a;
                    else
                        x = 0x03ba;

                    break;
                case 0x8b:
                    if (shift)
                        x = 0x039b;
                    else
                        x = 0x03bb;
                    break;
                case 0x8c:
                    if (shift)
                        x = 0x039c;
                    else
                        x = 0x03bc;

                    break;
                case 0x8d:
                    if (shift)
                        x = 0x039d;
                    else
                        x = 0x03bd;
                    break;
                case 0x8e:
                    if (shift)
                        x = 0x039e;
                    else
                        x = 0x03be;
                    break;
                case 0x8f:
                    if (shift)
                        if (tonos)
                            x = 0x038c;
                        else
                            x = 0x039f;
                    else
                        if (tonos)
                            x = 0x03cc;
                        else
                            x = 0x03bf;
                    break;
                case 0x90:
                    if (shift)
                        x = 0x03a0;
                    else
                        x = 0x03c0;
                    break;
                case 0x91:
                    if (shift)
                        x = 0x03a1;
                    else
                        x = 0x03c1;
                    break;
                case 0x92:
                    x = 0x03c2;
                    break;
                case 0x93:
                    if (shift)
                        x = 0x03a3;
                    else
                        x = 0x03c3;
                    break;
                case 0x94:
                    if (shift)
                        x = 0x03a4;
                    else
                        x = 0x03c4;
                    break;
                case 0x95:
                    if (shift)
                        if (tonos)
                            x = 0x038e;
                        else
                            if (dialitika)
                                x = 0x03ab;
                            else
                                x = 0x03a5;
                    else
                        if (tonos)
                            if (dialitika)
                                x = 0x03b0;
                            else
                                x = 0x03cd;

                        else
                            if (dialitika)
                                x = 0x03cb;
                            else
                                x = 0x03c5;
                    break;
                case 0x96:
                    if (shift)
                        x = 0x03a6;
                    else
                        x = 0x03c6;
                    break;
                case 0x97:
                    if (shift)
                        x = 0x03a7;
                    else
                        x = 0x03c7;
                    break;
                case 0x98:
                    if (shift)
                        x = 0x03a8;
                    else
                        x = 0x03c8;

                    break;

                case 0x99:
                    if (shift)
                        if (tonos)
                            x = 0x038f;
                        else
                            x = 0x03a9;
                    else
                        if (tonos)
                            x = 0x03ce;
                        else
                            x = 0x03c9;
                    break;
                default:
                    x = inp[pos];
                    break;
            }
            pos++;

            return x;
        }

        //return new ulong();
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM