我正在Socket为我的网络客户端使用课程.我无法使用,HttpWebRequest因为它不支持socks代理.所以我必须自己解析标题并处理分块编码.对我来说最困难的是确定内容的长度,所以我必须逐字节地读取它.首先,我必须使用ReadByte()查找最后一个标题("\ r \n\r \n"组合),然后检查正文是否具有传输编码.如果它,我必须阅读块的大小等:
public void ParseHeaders(Stream stream)
{
while (true)
{
var lineBuffer = new List<byte>();
while (true)
{
int b = stream.ReadByte();
if (b == -1) return;
if (b == 10) break;
if (b != 13) lineBuffer.Add((byte)b);
}
string line = Encoding.ASCII.GetString(lineBuffer.ToArray());
if (line.Length == 0) break;
int pos = line.IndexOf(": ");
if (pos == -1) throw new VkException("Incorrect header format");
string key = line.Substring(0, pos);
string value = line.Substring(pos + 2); …Run Code Online (Sandbox Code Playgroud) Laravel 5.5具有新的API资源功能,它可以很好地将调用重定向到模型属性(如$this->id).我用ide-helper:models它为类型提示所有模型属性的模型生成phpdoc.但是,这不适用于资源,我得到"通过魔术方法访问的字段"波浪形.有没有办法将它指向模型的phpdoc而不复制它?
它不仅适用于我或每个人吗?每次我在lambda(后面的点Enumerable)中写'foreach'块时,它都不起作用:
Action t = ()=>
{
foreach (var item in Enumerable.)
{
}
};
Run Code Online (Sandbox Code Playgroud)
知道为什么它不能在这种情况下工作吗?
我有VS 2010 SP1
更新:它不是关于Enumerable,它是关于任何对象.我可以尝试编写new object().并遇到同样的问题.
通常我必须编写如下布局代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" />
Run Code Online (Sandbox Code Playgroud)
我想做这样的事情:
<LinearLayout xmlns="http://schemas.android.com/apk/res/android"
layout_width="fill_parent"
layout_height="fill_parent"
orientation="vertical" >
Run Code Online (Sandbox Code Playgroud)
但是这段代码运行不正常.为什么?
第二个问题:为什么元素namen在CamelCase中,属性在under_score中?
我正在尝试使用套接字通过代理连接到HTTPS服务器.据我所知,在使用HTTP代理时,应该将套接字连接到它,然后与它进行交互,因为它是真正的服务器.使用HTTP这种方法可行,但HTTPS不是.为什么?
这是连接到HTTPS服务器的简单程序
using System;
using System.Text;
using System.Net.Sockets;
using System.Net.Security;
namespace SslTcpClient
{
public class SslTcpClient
{
public static void Main(string[] args)
{
string host = "encrypted.google.com";
string proxy = "127.0.0.1";//host;
int proxyPort = 8888;//443;
// Connect socket
TcpClient client = new TcpClient(proxy, proxyPort);
// Wrap in SSL stream
SslStream sslStream = new SslStream(client.GetStream());
sslStream.AuthenticateAsClient(host);
// Send request
byte[] request = Encoding.UTF8.GetBytes(String.Format("GET https://{0}/ HTTP/1.1\r\nHost: {0}\r\n\r\n", host));
sslStream.Write(request);
sslStream.Flush();
// Read response
byte[] buffer = new byte[2048];
int bytes;
do
{ …Run Code Online (Sandbox Code Playgroud) 我在ssh config中正确指向了密钥文件:
$ cat ~/.ssh/config
Host <host>
IdentityFile /cygdrive/v/poma.pem
$ ssh git@<host>
PTY allocation request failed on channel 0
Welcome to GitLab, Roman!
Connection to <host> closed.
Run Code Online (Sandbox Code Playgroud)
并使用cygwin的git
$ which git
/usr/bin/git
$ git --version
git version 2.1.4
$ /cygdrive/c/Program\ Files\ \(x86\)/Git/bin/git.exe --version
git version 1.9.5.msysgit.1
Run Code Online (Sandbox Code Playgroud)
但是当我尝试推送它时会显示密码提示:
$ git remote -v
origin git@<host>:poma/deploy.git (fetch)
origin git@<host>:poma/deploy.git (push)
$ git push -u origin master
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and …Run Code Online (Sandbox Code Playgroud) 我正在尝试在注册延续任务后开始一项任务。但在await Task.Delay()调用后,Continue 会立即触发。
using System;
using System.Linq;
using System.Threading.Tasks;
namespace ConsoleApplication30
{
class Program
{
static void Main(string[] args)
{
var task = new Task(async delegate {
Console.WriteLine("Before delay");
await Task.Delay(1000);
Console.WriteLine("After delay");
});
task.ContinueWith(t => {
Console.WriteLine("ContinueWith");
});
task.Start();
Console.ReadLine();
}
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
Before delay
ContinueWith
After delay
Run Code Online (Sandbox Code Playgroud)
这里有什么问题吗?
我想创建一个绑定到热键的小部件,该热键在提示下方以富文本格式打印当前命令描述,然后在按键后将其删除。像这样(简化):
\nwidget() {\n zle -R "ls - list files"\n read -k 1\n}\nzle -N widget\nbindkey '\\eg' widget\nRun Code Online (Sandbox Code Playgroud)\n但zle -R只能打印纯文本,甚至不支持换行。我想打印带有颜色和换行符的文本,例如^[[31mls^[[00m - list files.
我可以使用什么方法来做到这一点?
\n对于我的用例来说,仅将其打印到常规标准输出然后初始化新提示将是一个糟糕的用户界面。这将是一个不受欢迎的解决方案。
\n我希望它出现在提示符下方,并且与 zsh-autocomplete、ctrl+R 或 fzf 类似地工作。输出没有任何复杂的交互,它只出现在热键上,然后在按键时消失。
\nzsh-autocomplete 存储库的作用类似,但我不知道它是如何完成的。
\n实际上我需要类似的东西,List<KeyValuePair<T, U>>但我希望能够像字典一样初始化它(即new KeyValuePair每次都不写).像这样:
Dictionary<string, string> dic = new Dictionary<string, string>
{
{ "key1", "value1"},
{ "key2", "value2"}
};
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建基本的角度应用程序,它会抛出错误
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>
<script type="text/javascript">
var angularApp = angular.module('angularApp', []);
angularApp.controller('Ctrl', function($scope) {});
</script>
</head>
<body>
<div ng-app ng-controller="Ctrl"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
错误:
Error: [ng:areq] http://errors.angularjs.org/1.4.3/ng/areq?p0=Ctrl&p1=not%20a%20function%2C%20got%20undefined
at Error (native)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:6:416
at Sb (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:22:18)
at Qa (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:22:105)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:79:497
at x (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:59:501)
at S (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:60:341)
at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:54:384)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:53:444
at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:19:481'
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
c# ×5
.net ×3
http ×2
sockets ×2
.net-4.5 ×1
android ×1
angularjs ×1
async-await ×1
cygwin ×1
git ×1
intellisense ×1
javascript ×1
laravel ×1
laravel-5.5 ×1
namespaces ×1
php ×1
phpstorm ×1
shell ×1
ssh ×1
terminal ×1
xml ×1
zsh ×1
zsh-zle ×1