找回密码
 立即注册

QQ登录

只需一步,快速开始

Twelve

注册会员

2

主题

4

帖子

87

积分

注册会员

积分
87
最新发帖
Twelve
注册会员   /  发表于:2021-3-4 22:56  /   查看:1478  /  回复:2
50金币

keyword:  c#爬虫 GB2313 webapi
ok,是这样的,需要写一个爬虫,访问别的网站,获取数据,通过API把数据传到活字格前端页面。
功能在c# 窗口页面是已经实现的了。


然后需要打包成一个DLL文件,上传到活字格设计器。
我又重新写了一个c#类库,代码跟上面的代码基本相似,打包出来,到前端页面验证。

此时报错

错误代码同下
  1. Request Exception Happened-------------------------------
  2. Path/customapi/testgetapi/QueryInnerProvince
  3. UserName:Administrator
  4. QueryString:?txzh=140400202102080012
  5. Request Data:
  6. txzh:-----------------------
  7. 140400202102080012
  8. ------------------------------
  9. {
  10.   "ClassName": "System.ArgumentException",
  11.   "Message": "'gb2312' is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.",
  12.   "Data": {
  13.     "$type": "System.Collections.ListDictionaryInternal, System.Private.CoreLib",
  14.     "App Name": "I2LR43YZVM2M12ZL5XAMAAEGJUYAP2GP",
  15.     "App Version": "6.0.102.0",
  16.     "Timestamp of the exe": "5e597f86",
  17.     "Assembly Name": "System.Private.CoreLib",
  18.     "Version of faulting assembly": "4.700.20.47201",
  19.     "Timestamp of faulting module": "8b0e5337",
  20.     "MethodDef": "25bb",
  21.     "IL Offset of faulting instruction": "95",
  22.     "Exception Type": "System.ArgumentException",
  23.     "NIL": ""
  24.   },
  25.   "InnerException": null,
  26.   "HelpURL": null,
  27.   "StackTraceString": "   at System.Text.EncodingTable.InternalGetCodePageFromName(String name)
  28.    at System.Text.EncodingTable.GetCodePageFromName(String name)
  29.    at System.Text.Encoding.GetEncoding(String name)
  30.    at 活字格webApi实现.TestGetApi.QueryInnerProvince()",
  31.   "RemoteStackTraceString": null,
  32.   "RemoteStackIndex": 0,
  33.   "ExceptionMethod": null,
  34.   "HResult": -2147024809,
  35.   "Source": "System.Private.CoreLib",
  36.   "WatsonBuckets": null,
  37.   "ParamName": "name"
  38. }
复制代码

于是我又写了一个API,遍历了编码格式。
  1. 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

附件: 您需要 登录 才可以下载或查看,没有帐号?立即注册

最佳答案

查看完整内容

你好,打断点看了一下,不是活字格编码不支持的问题,应该是HttpWebRequest请求的编码格式问题,要转换。 帮你查了一下资料,可以参考改一下源码哈。 https://zhuanlan.zhihu.com/p/87004298

2 个回复

倒序浏览
最佳答案
最佳答案
Erik.Xue讲师达人认证 悬赏达人认证 活字格认证 Wyn认证
超级版主   /  发表于:2021-3-4 22:56:21
来自 3#
你好,打断点看了一下,不是活字格编码不支持的问题,应该是HttpWebRequest请求的编码格式问题,要转换。
帮你查了一下资料,可以参考改一下源码哈。


https://zhuanlan.zhihu.com/p/87004298

回复 使用道具 举报
Twelve
注册会员   /  发表于:2021-3-4 22:58:00
2#
相关资料:
C#编写服务器端API 视频教程:https://help.grapecity.com.cn/pages/viewpage.action?pageId=3867574

调试服务端自定义Web API文档:https://help.grapecity.com.cn/pages/viewpage.action?pageId=38476833
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部