标签: send

如何呈现XML模板,然后在Ruby on Rails 3.2.8中使用SEND_DATA?

任何人都可以帮我处理XML模板渲染和send_data吗?

我有一个控制器:

def show
  @calculation = Calculation.find(params[:id])

  respond_to do |format|
    format.html # show.html.erb
    format.json { render json: @calculation }
    format.xml {send_data( :partial=>show.xml.erb, :filename => "my_file.xml" ) }
    format.pdf { render :format=>false}
  end
end
Run Code Online (Sandbox Code Playgroud)

但是我有很多错误,"堆栈级别太深"

如果我使用

{send_data( @calculation, :filename => "my_file.xml" ) }
Run Code Online (Sandbox Code Playgroud)

我得到XML文件,但不是我的模板...

编辑: 我有办法!

format.xml do  
  stream = render_to_string(:template=>"calculations/show" )  
  send_data(stream, :type=>"text/xml",:filename => "test.xml")
end
Run Code Online (Sandbox Code Playgroud)

一切正常!

ruby ruby-on-rails send

14
推荐指数
1
解决办法
6498
查看次数

sendmsg如何工作?

如您所知sendmsg有此声明:

int sendmsg(int s, const struct msghdr *msg, int flags);

msghdr结构有这种形式:

struct msghdr {
    void         * msg_name;     /* optional address */
    socklen_t    msg_namelen;    /* size of address */
    struct iovec * msg_iov;      /* scatter/gather array */
    size_t       msg_iovlen;     /* # elements in msg_iov */
    void         * msg_control;  /* ancillary data, see below */
    socklen_t    msg_controllen; /* ancillary data buffer len */
    int          msg_flags;      /* flags on received message */
};
Run Code Online (Sandbox Code Playgroud)

如你所见,msghdr有一个缓冲区数组,iovec并且缓冲区数为msg_iovlen.我想知道sendmsg如何发送这些缓冲区.它是连接所有缓冲区并发送还是以for循环发送?

c sockets send

13
推荐指数
1
解决办法
2万
查看次数

Linux Socket:如何在客户端程序中检测断开的网络?

我正在调试基于ac的linux socket程序.正如网站上提供的所有示例一样,我应用了以下结构:

sockfd= socket(AF_INET, SOCK_STREAM, 0);

connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr));

send_bytes = send(sockfd, sock_buff, (size_t)buff_bytes, MSG_DONTWAIT);
Run Code Online (Sandbox Code Playgroud)

当删除服务器关闭其服务器程序时,我可以检测到断开连接.但是如果我拔掉以太网电缆,send函数仍会返回正值而不是-1.

假设我无法更改服务器端,如何检查客户端程序中的网络连接?

c sockets linux send disconnection

13
推荐指数
1
解决办法
5万
查看次数

使用"发送"而不是普通的方法调用有什么意义?

据我了解'发送'方法,这个

some_object.some_method("im an argument")
Run Code Online (Sandbox Code Playgroud)

与此相同

some_object.send :some_method, "im an argument"
Run Code Online (Sandbox Code Playgroud)

那么使用'send'方法有什么意义呢?

ruby methods send

13
推荐指数
2
解决办法
2522
查看次数

如何从Java发送短信?

我想从Web应用程序向特定的移动设备发送SMS,并仅接收他的回复并查看Web应用程序.是否可以使用Java技术创建?

java sms send

11
推荐指数
1
解决办法
4万
查看次数

使用生成器来编写文件的标题和正文是pythonic吗?

如果我要用这个内容写一个文件:

#You have been defeated!
#It's merely a flesh wound!
We are the knights who say Ni!
We are the knights who say Ni!
We are the knights who say Ni!
Run Code Online (Sandbox Code Playgroud)

那么用发送器使用发送器来做它会非常非pythonic吗?我从未见过其他地方使用的发电机.

def write(file, header):

    with open(file,'w') as f:
        f.write(header)
        line = (yield)
        while True:
            f.write(line)
            line = (yield)

    return

file='holygrail.txt'
header="#You have been defeated!\n#It's merely a flesh wound!\n"
generator = write(file,header)
generator.send(None)
for i in range(3):
    generator.send('We are the knights who say Ni!\n')
generator.close()
Run Code Online (Sandbox Code Playgroud)

我问,因为上面的方法对我非常有益,而不是在contextlib堆栈中打开多个不同的文件流.如果我像这样写我的文件,我根本不必使用contextlib模块.

我之前从未问过这样的问题,我不知道它是否属于stackoverflow.

python file-io generator send python-3.x

11
推荐指数
1
解决办法
285
查看次数

如何通过MailChimp 3.0 api发送电子邮件?

我试图通过mailchimp api 3.0版在php中发送电子邮件,但我没有运气.这是我的代码:

$postString = '{
        "message": {
            "html": "this is the emails html content",
            "text": "this is the emails text content",
            "subject": "this is the subject",
            "from_email": "xxx@dyyy.sk",
            "from_name": "John",
            "to_email": "aaa.bbb@gmail.com",
            "to_name": "Anton",
            "track_opens": false,
            "track_clicks": false
        }}';

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->api_endpoint);
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
        curl_setopt($ch, CURLOPT_USERPWD, 'drewm:'.$this->api_key);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/vnd.api+json', 'Content-Type: application/vnd.api+json'));
        curl_setopt($ch, CURLOPT_USERAGENT, 'DrewM/MailChimp-API/3.0 (github.com/drewm/mailchimp-api)');
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true );
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verify_ssl);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, …
Run Code Online (Sandbox Code Playgroud)

php email send mailchimp

11
推荐指数
2
解决办法
3万
查看次数

Spring Kafka异步发送调用块

我正在使用Spring-Kafka版本1.2.1,当Kafka服务器关闭/无法访问时,异步发送调用阻塞一段时间.它似乎是TCP超时.代码是这样的:

ListenableFuture<SendResult<K, V>> future = kafkaTemplate.send(topic, key, message);
future.addCallback(new ListenableFutureCallback<SendResult<K, V>>() {
    @Override
    public void onSuccess(SendResult<K, V> result) {
        ...
    }

    @Override
    public void onFailure(Throwable ex) {
        ...
    }
});
Run Code Online (Sandbox Code Playgroud)

我已经快速浏览了Spring-Kafka代码,它似乎只是将任务传递给kafka客户端库,将回调交互转换为未来的对象交互.看看kafka客户端库,代码变得更加复杂,我没有花时间去理解它,但我想它可能在同一个线程中进行远程调用(元数据,至少?).

作为用户,我期望返回未来的Spring-Kafka方法立即返回,即使远程kafka服务器无法访问.

如果我的理解是错误的,或者如果这是一个错误,任何确认将是受欢迎的.我现在最终将它变为异步.

另一个问题是Spring-Kafka文档在开始时说它提供了同步和异步发送方法.我找不到任何不返回期货的方法,也许文档需要更新.

如果需要,我很乐意提供任何进一步的细节.谢谢.

spring asynchronous send producer apache-kafka

11
推荐指数
2
解决办法
8475
查看次数

Discord.js 向特定频道发送消息

我没有实现一些非常简单的事情。我无法向特定频道发送消息。我浏览了有关堆栈溢出的文档和类似线程。

client.channels.get().send()

不起作用。它不是一个函数。我也不认为它是官方文档中 Channel 类的方法,但到目前为止我发现的每个线程都告诉我使用它。

我设法让机器人通过监听消息然后使用来回复消息,message.reply()但我不想要那样。我希望我的机器人在特定频道中说些什么client.on('ready')

我错过了什么?

bots send node.js discord.js

11
推荐指数
2
解决办法
7万
查看次数

使用python将一些键发送到非活动窗口

我正在尝试使用python将一些密钥发送到非活动窗口/进程/程序(win32/64).已经阅读了关于pywinauto和SendKeys的信息,但是他们都在发送密钥之前激活了窗口.

有没有办法使用非活动窗口而不激活它?

如果有人发布简单的示例/片段会很棒.

谢谢.

python windows key send sendkeys

10
推荐指数
1
解决办法
8695
查看次数