keyword: c#爬虫 GB2313 webapi
ok,是这样的,需要写一个爬虫,访问别的网站,获取数据,通过API把数据传到活字格前端页面。
功能在c# 窗口页面是已经实现的了。
然后需要打包成一个DLL文件,上传到活字格设计器。
我又重新写了一个c#类库,代码跟上面的代码基本相似,打包出来,到前端页面验证。
此时报错
错误代码同下
- Request Exception Happened-------------------------------
- Path/customapi/testgetapi/QueryInnerProvince
- UserName:Administrator
- QueryString:?txzh=140400202102080012
- Request Data:
- txzh:-----------------------
- 140400202102080012
- ------------------------------
- {
- "ClassName": "System.ArgumentException",
- "Message": "'gb2312' is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.",
- "Data": {
- "$type": "System.Collections.ListDictionaryInternal, System.Private.CoreLib",
- "App Name": "I2LR43YZVM2M12ZL5XAMAAEGJUYAP2GP",
- "App Version": "6.0.102.0",
- "Timestamp of the exe": "5e597f86",
- "Assembly Name": "System.Private.CoreLib",
- "Version of faulting assembly": "4.700.20.47201",
- "Timestamp of faulting module": "8b0e5337",
- "MethodDef": "25bb",
- "IL Offset of faulting instruction": "95",
- "Exception Type": "System.ArgumentException",
- "NIL": ""
- },
- "InnerException": null,
- "HelpURL": null,
- "StackTraceString": " at System.Text.EncodingTable.InternalGetCodePageFromName(String name)
- at System.Text.EncodingTable.GetCodePageFromName(String name)
- at System.Text.Encoding.GetEncoding(String name)
- at 活字格webApi实现.TestGetApi.QueryInnerProvince()",
- "RemoteStackTraceString": null,
- "RemoteStackIndex": 0,
- "ExceptionMethod": null,
- "HResult": -2147024809,
- "Source": "System.Private.CoreLib",
- "WatsonBuckets": null,
- "ParamName": "name"
- }
复制代码
于是我又写了一个API,遍历了编码格式。
- Unicode Unicode (Big-Endian) Unicode (UTF-32) Unicode (UTF-32 Big-Endian) US-ASCII Western European (ISO) Unicode (UTF-7) Unicode (UTF-8)
复制代码 可以看到打包后的程序并不支持gb2313。
于是我把gb2313换成了UTF-8,结果显示是显示了,不过显示的是乱码,让我更肯定是编码格式的问题。
因为原本学的不是C#,又查了差不多要一天的资料,眼睛有些酸痛,感觉我解决不了这个问题啊,有没有哪位大佬能帮忙解决一下这个问题。
测试是直接在浏览器调API测试,所以下方这个活字格文件并没有啥太大用处。
相关资料:
C#编写服务器端API
调试服务端自定义Web API
|