首页 \ 问答 \ 在C#中解析原始HTTP响应以获取状态码(Parse a raw HTTP Response in C# to get the Status Code)

在C#中解析原始HTTP响应以获取状态码(Parse a raw HTTP Response in C# to get the Status Code)

有没有简单的方法来解析HTTP响应字符串,如下所示:

"HTTP/1.1 200 OK\r\nContent-Length: 1433\r\nContent-Type: text/html\r\nContent-Location: http://server/iisstart.htm\r\nLast-Modified: Fri, 21 Feb 2003 23:48:30 GMT\r\nAccept-Ranges: bytes\r\nETag: \"09b60bc3dac21:1ca9\"\r\nServer: Microsoft-IIS/6.0\r\nX-Po"

我想获得状态代码。 我不一定需要将其转换为HttpResponse对象,但这是可以接受的,并且仅解析出状态码。 我能解析到HttpStatusCode枚举吗?

我使用基于套接字的方法,无法改变我得到我的回应的方式。 我只会使用这个字符串。


Is there a simple way to parse an HTTP Response string such as follows:

"HTTP/1.1 200 OK\r\nContent-Length: 1433\r\nContent-Type: text/html\r\nContent-Location: http://server/iisstart.htm\r\nLast-Modified: Fri, 21 Feb 2003 23:48:30 GMT\r\nAccept-Ranges: bytes\r\nETag: \"09b60bc3dac21:1ca9\"\r\nServer: Microsoft-IIS/6.0\r\nX-Po"

I would like to get the Status Code. I do not necessarily need to turn this in to an HttpResponse object, but that would be acceptable as well as just parsing out the Status Code. Would I be able to parse that into the HttpStatusCode enum?

I am using a sockets based approach and cannot change the way I am getting my response. I will only have this string to work with.


原文:https://stackoverflow.com/questions/6779303
更新时间:2022-03-04 11:03

最满意答案

我不得不在Sparrow框架中做类似的事情,你应该能够在本次论坛回复中将你需要的部分从代码中提取出来: http : //forum.sparrow-framework.org/topic/spdisplayobjectscreenshot

编辑:也这个职位http://forum.sparrow-framework.org/topic/taking-screenshots


I had to do something similar in the Sparrow Framework a while back, you should be able to pull the parts you need out of the code in this forum reply: http://forum.sparrow-framework.org/topic/spdisplayobjectscreenshot

EDIT: Also this post http://forum.sparrow-framework.org/topic/taking-screenshots

相关问答

更多
  • 我的应用程序不完全是一款游戏,但它一次在屏幕上使用3个GLViews (理论上更多,但目前有三个)。 这样做没有任何问题,但是文档说GLViews与其他视图混合GLViews处理速度降低一些。 我不记得我读到的地方了。 长话短说,如果可以,我会说避免它。 如果您的应用程序完全基于GL,那么为什么不将它全部集成在一起呢? 我的应用程序不完全基于GL,所以我需要GL绘图的多个“窗口”。 My app is not exactly a game, but it uses 3 GLViews on the scre ...
  • 我已经弄明白了! /** * Method to take a screenshot programmatically */ private void takeScreenshot(){ GoogleMap.SnapshotReadyCallback callback = new GoogleMap.SnapshotReadyCallback() { @Override public void onSnapshotReady(Bitmap bitmap) { ...
  • 不确定您的screenshotImage对象是否具有Image。 我尝试下面的代码,它工作正常。 import UIKit class ViewController: UIViewController { override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if (segue.identifier == "screenshotEmbed") { let ...
  • 很酷的家伙(DeltaKosh)在htmlgameDevs帮助我。 他说,当您为截图创建引擎或呈现PNG文件时,您必须以这种方式定义它: engine = new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: true, stencil: true }); 我还添加了一个等待一秒钟的循环,直到场景渲染到截屏后 var scene = createScene(); var booleanR = false; var size = 512; ...
  • 如上所述,你可以试试这个 - (UIImage*) renderToImage { UIGraphicsBeginImageContextWithOptions(self.frame.size, NO, 0.0); [self.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndIma ...
  • 我不得不在Sparrow框架中做类似的事情,你应该能够在本次论坛回复中将你需要的部分从代码中提取出来: http : //forum.sparrow-framework.org/topic/spdisplayobjectscreenshot 编辑:也这个职位http://forum.sparrow-framework.org/topic/taking-screenshots I had to do something similar in the Sparrow Framework a while back ...
  • 将您的代码更改为以下内容: func captureScreen() -> UIImage { UIGraphicsBeginImageContextWithOptions(self.view.frame.size, false, 0); self.view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true) let image:UIImage = UIGraphicsGetImageFromCurrentImageContext( ...
  • 在窗口有机会绘制任何内容之前,您正在截取屏幕截图。 因为只有在使用pyglet.app.run()启动事件处理循环后才会调用on_draw()事件处理程序。 一种可能的解决方案是将屏幕截图功能也放入事件处理程序中,例如: @window.event def on_key_press(symbol, modifiers): pyglet.image.get_buffer_manager().get_color_buffer().save('screenshot1.png') 这样,屏幕截图仅在您按下 ...
  • 您可以强制CCDirector将内容绘制到帧缓冲区。 在设置新场景后立即运行此命令。 根据cocos2d版本,您可以执行以下操作: [[CCDirector sharedDirector] visit]; 要么 [[CCDirector sharedDirector] drawScene]; 强制立即更新帧缓冲区。 否则cocos2d将在下一个显示链接刷新事件上绘制,该事件可能在下一帧之前不会发生,并且可能延迟甚至更长,因为所有耗时的设置代码都发生在第一帧中。 You can force the CCD ...
  • 在示例代码中,您将在图像上下文中呈现表视图的图层。 这将始终快照整个表视图。 您可以在快照之前获取评论者的建议并调整表格视图的单元格。 或者,您可以快照要渲染的单元格的图层。 例如: extension UITableView { func snapshotRows(at indexPaths: Set) -> UIImage? { guard !indexPaths.isEmpty else { return nil } var rec ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。